2016-12-29 65 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