我对VBA比较陌生。我试图遍历一个表,并在每次循环时拉出一个不同的值。
Sub Macro3()
Dim i As Integer
Windows("CC_1000H.xlsx").Activate
Sheets("CC_1000H").Select
Dim Count_Accounts As Integer
Dim NewLine As Integer
Count_Accounts = Worksheets("Sheet1").Cells(4, "H").Value
i = 0
Do Until i = Count_Accounts
i = i + 1
NewLine = Worksheets("Sheet1").Cells(i + 1, "F").Value
'Rows("4:4").Select Rows(NewLine).Select
'(More code)
Loop
End Sub
第一次通过这个循环,代码工作正常。第二次通过,Worksheets的值(" Sheet1")。Cells(i + 1," F")。值为空,NewLine为0.它没有似乎无论我如何引用单元格值,我是什么,或者即使我使用我。它第二次不会读一个单元格。
有谁知道我在这里做错了什么?
由于
答案 0 :(得分:0)
希望你能找到这个
Sub Macro3()
Dim i As Long
Windows("CC_1000H.xlsx").Activate
Sheets("CC_1000H").Select
Dim Count_Accounts As Long
Dim NewLine As Long
Count_Accounts = Worksheets("Sheet1").Range("H" & Rows.Count).End(xlUp).Row
i = 0
Do Until i = Count_Accounts
i = i + 1
NewLine = Worksheets("Sheet1").Range("F" & i + 1).Value
Loop
End Sub