I have a while loop that scraps the web for data. Within that while statement there is an If statement. When the condition for the if statement is true it prints to my immediate window. I need it to print the first item of the list to A1, the second to A2 and so on and so forth until the subroutine is complete. Can anyone help me with this? I feel like this should be rather easy to accomplish, however I felt that way 3 hours ago when I began searching for the solution to this problem.
This is the current code That contains the if statement.
If Left(var.innerText, 4) = "I123" Then
Newvar = Mid(var.outerHTML, 44, 12)
Range("A1:A200").Value = Newvar
End If
This is an example of the output that is displayed in the immediate window when I execute the code.
I12307025601
I12307025701
I12307025801
I12307025901
I12307026001
I cannot find a way to have it print this list starting on A1 and then go to A2 and so on.
At the beginning of your Sub place a declaration
Dim rowcounter as Long
If Left(var.innerText, 4) = "I123" Then
rowcounter = rowcounter + 1 'added
Newvar = Mid(var.outerHTML, 44, 12)
Range("A" & rowcounter).Value = Newvar 'edited
End If
This place the values to the ActiveSheet or the sheet where the code is placed in the sheet's code pane.
If you want a specific Sheet to use declare it in this way
Worksheets("the_sheet_name").Range("A" & rowcounter).Value = Newvar