这部分代码打开一个Excel文件,并将范围D4:D5中的数据加载到一个主表中。
GetData myFile, "Vystupna_kontrola", "D4:D5", Sheets("test_zila").Range(Sheets("test_zila").Cells(Sheets("test_zila").Cells(Rows.Count, 1).End(xlUp).Row + 1, 1), Sheets("test_zila").Cells(Sheets("test_zila").Cells(Rows.Count, 1).End(xlUp).Row + 1, 1)), True, False
我想将D4:D5范围用作将从数组加载的变量。
Dim nazov(1 To 2) As String
nazov(1) = "D4:D5"
nazov(2) = "S4:S5"
For i = 2 To UBound(nazov)
GetData myFile, "Vystupna_kontrola", "nazov(i)", Sheets("test_zila").Range(Sheets("test_zila").Cells(Sheets("test_zila").Cells(Rows.Count, i).End(xlUp).Row + 1, i), Sheets("test_zila").Cells(Sheets("test_zila").Cells(Rows.Count, i).End(xlUp).Row + 1, i)), True, False
Next i
但这不起作用。你能帮我解释一下代码吗?
答案 0 :(得分:2)
从i = 1
开始循环并移除"
,以便您可以传递数组的值nazov
For i = 1 To UBound(nazov)
GetData myFile, "Vystupna_kontrola", nazov(i), Sheets("test_zila").Range(Sheets("test_zila").Cells(Sheets("test_zila").Cells(Rows.Count, i).End(xlUp).Row + 1, i), Sheets("test_zila").Cells(Sheets("test_zila").Cells(Rows.Count, i).End(xlUp).Row + 1, i)), True, False
Next i