我有一个如下代码,我想在下一行开始新循环时将“add”重置为1。
Sub Group()
DataBook = ThisWorkbook.Name
Dim i As Long
RowCount = 1
RowCount2 = 1
Add = 1
For i = 19 To 1819
If Workbooks(DataBook).Sheets("Template").Range("G" & i).IndentLevel = 8 Then
Workbooks(DataBook).Sheets("Sheet1").Cells(RowCount, 2) = Workbooks(DataBook).Sheets("Template").Range("G" & i).Value
RowCount = RowCount + 1
If Workbooks(DataBook).Sheets("Template").Range("G" & i - Add).IndentLevel = 7 Then
Workbooks(DataBook).Sheets("Sheet1").Cells(RowCount2, 1) = Workbooks(DataBook).Sheets("Template").Range("G" & i - Add)
RowCount2 = RowCount2 + 1
Add = Add + 1
End If
End If
Next i
End Sub
答案 0 :(得分:2)
切换这两行:
Add = 1
For i = 19 To 1819
I.e:
For i = 19 To 1819
Add = 1