0
我尝试使用vba脚本将一些文本附加到我的excel文档中的每个标题列。在追加到单元格时在excel vba中输入类型不匹配
Dim c As Range
For Each c In Sheet13.Rows(1)
c.Value = c.Value & "bleh"
Next
但是,这给了我一个类型不匹配的错误13,我不知道为什么。 单元格只包含文本。
我尝试使用vba脚本将一些文本附加到我的excel文档中的每个标题列。在追加到单元格时在excel vba中输入类型不匹配
Dim c As Range
For Each c In Sheet13.Rows(1)
c.Value = c.Value & "bleh"
Next
但是,这给了我一个类型不匹配的错误13,我不知道为什么。 单元格只包含文本。
For Each c In Sheet13.UsedRange.Rows(1).Cells
.Cells
获取单个单元格而不是整行。
.UsedRange
避免到行尾(XFD1
)。你可以调整它得到唯一的非空的,恒定的细胞,即:
For Each c In Sheet13.UsedRange.Rows(1).SpecialCells(xlCellTypeConstants)
尝试下面的代码:
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
优秀的感谢。当定时器耗尽时,请将其标记为正确。 – CathalMF