I have written a vba code that has a "for next"
loop 1 to 10 and displays the result in respective rows in ColumnA, i want when it reaches row 5 the macro should automatically create a new sheet named "New sheet" and the "for next"
continues from 6 til it reaches 10. I'm new to VBA and the code I wrote doesn't seem to work.
My VBA code:
Sub test()
Dim a As Long
Dim WS As Worksheet
Set WS = Worksheets.Add(After:=Worksheets(1))
WS.Name = "New Sheet"
n = 1
col1 = 1
For a = 1 To 10
If n <= 5 Then
Cells(n, col1).Value = a
n = n + 1
End If
If n > 5 Then
WS.Cells(n, 1).Value = a
n = n + 1
End If
Next a
End Sub