从string数组写入单元格时出现“无效限定符”
我有一个简单的macros设置一些常见的标题和格式:
Dim colString(1 To 17, 1 To 2) As String Dim i As Integer colString(1, 1) = "NA" ' Column header colString(1, 2) = "23" ' Column background color index colString(2, 1) = "NB" colString(2, 2) = "1" ' etc, until (17, 2) For i = 1 To 17 With Cells(1, i) .Value = colString(i, 1).Value .Interior.ColorIndex = CInt(colString(i, 2)) .Font.Color = vbWhite '.Font.Bold End With Next i
我在这一行收到一个错误:
.Value = colString(i, 1).Value
该错误读取“无效的限定符”与“colString”突出显示。
我不明白为什么我得到这个错误,或者如何改变它。 由于我遍历一行,使用单元格似乎是最简单的路线? Google,MrExcel和SO什么也没有。
你的数组是键入的string,而不是任何types的对象,所以它的项目没有属性或方法。 因此,您需要删除.Value
(并按照您在下面的行中使用它):
With Cells(1, i) .Value = colString(i, 1) .Interior.ColorIndex = CInt(colString(i, 2)) .Font.Color = vbWhite '.Font.Bold End With
.Value = colString(i, 1)
数组不能取.Value。