我正在尝试将1分配给变量firstCol
,将2分配给变量secondCol
...
[当我开始循环通过colHeaders
时,循环变量Header
不具有任何值。我知道语法不正确,并且为Header
指定了num
,但我认为这是解释我要执行的操作的最佳方法。
是否可以遍历变量?
Dim colHeaders() As Variant
Dim Dict As New Scripting.Dictionary
Set Dict = New Scripting.Dictionary
colHeaders = Array(firstCol, secondCol, thirdCol, fourthCol, fifthCol)
num = 1
For Each Header In colHeaders
Header = num
num = num + 1
Next Header
Dim Dict As New Scripting.Dictionary
Set Dict = New Scripting.Dictionary
Dim colHeaders() As Variant
colHeaders = Array("firstCol", "secondCol", "thirdCol", "fourthCol", "fifthCol")
Dim num As Long
num = 1
Dim header As Variant
For Each header In colHeaders
Dict.Add header, num
num = num + 1
Next header
Debug.Print Dict("secondCol")