Reputation: 9
I have a code as below and i want to reset "add" as 1 when a new loop starts for the next row.
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
Upvotes: 0
Views: 94
Reputation: 12113
Switch these two lines:
Add = 1
For i = 19 To 1819
I.e:
For i = 19 To 1819
Add = 1
Upvotes: 2