Instead of looping to the next row and applying my code, the For Each Loop starts at the next cell on the same row.
I’m a beginner at VBA and all of my code came from the internet. I’m working with a form that I wanted to automatically fill up with the data in my Excel file.
So, the data are in a row, let’s say B3:D3, and my code would pick out the value of each cell and copy it to a textbox in the form. But instead of going to the next row or B4:D4, it loops and gets the data from C3:E3.
This is part of my code:
For Each Cell In Range("B3:D32").Cells
If Cell.Value = "" Then Exit For
Set obj = New Selenium.ChromeDriver
obj.Start
obj.Get "insert website here"
obj.FindElementByName("Enter Title").SendKeys (Cell.Offset(0, 0).Value)")
obj.FindElementByXPath("//button[@aria-describedby='cdk-describedby-message-6']").click
obj.FindElementByXPath("//img[@class='ng-star-inserted']").click
obj.FindElementByXPath("//input[@placeholder='Search for Employee/Group']").SendKeys (Cell.Offset(0, 3).Value)
It worked when I was going through the data in columns though and I’ve been through all questions and tutorials and I can’t seem to find the answer to go to the next row. Appreciate the help!
Goose is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
To travel row by row, you need to loop over the vertical vector:
For Each Cell In Range("B3:B32").Cells
Then you can use the Offset method to reach other cells in the same row:
Cell.Offset(0, 1)
Also, you can iterate through rows:
For i = 3 to 32
x = Rows(i).Cells(column)
' or
x = Cells(i, column1)
Next
where column and column1 are desired column numbers. column1 can also be expressed by letter like Cells(i, "A")
.