2016-12-29 43 views

回答

2
For Each c In Sheet13.UsedRange.Rows(1).Cells 

.Cells获取单个单元格而不是整行。

.UsedRange避免到行尾(XFD1)。你可以调整它得到唯一的非空的,恒定的细胞,即:

For Each c In Sheet13.UsedRange.Rows(1).SpecialCells(xlCellTypeConstants) 
+1

优秀的感谢。当定时器耗尽时,请将其标记为正确。 – CathalMF

2

尝试下面的代码:

Option Explicit 

Sub AddBleh() 

Dim c As Range 
Dim LastCol As Long 
Dim HeaderRng As Range 

With Sheet13 
    ' find last column with data in header row 
    LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column 

    ' set Range to only header row where there is data 
    Set HeaderRng = .Range(.Cells(1, 1), .Cells(1, LastCol)) 

    For Each c In HeaderRng.Cells 
     c.Value = c.Value & "bleh" 
    Next 

End With 

End Sub