excelvbaselenium-webdriverforeachrange

How can my For Each Loop loop to the next row?


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!


Solution

  • I'd like to post an "answer" to my question. It's in quotation because it's not a solution but an error in my original question. I don't need to select each cell in B3:D32. I just need to reference the cells in B3:B32 and the Offsets I indicated will pick out the other data in the cells I need.

    By changing the range in my code, I was able to make the code do what I wanted it to do.

    I came up with this "answer" because I was wondering why the "origin point" at B3 was moving to C3 on the next loop. Then I understood that my code points to all cells within B3:D32 so the "origin point" should move too.