WhocaresMcgee
WhocaresMcgee

Reputation: 23

Adding a Value to an input form in IE with VBA

I'm having trouble creating code entering data from a column in excel to my works Sale Pricing Page.My Loop to access all the inputs of the page works correctly, however, I'm having trouble iterating through the column range that the data is in, in excel.

Also I can not post the website I am using because it requires a log in from my work.

I feel like my problem is here

For Each SalePrice In Inputs

    SalePrice.innerText = ThisWorkbook.Sheets("Prices").Range("A1:A69")

Next

When I enter a range in the "A:A" format it will not input the cell text to the browser form. If I add just one cell range like "A1" or hardcode "test" it will add that cell value to the inputs.

Does anyone have any advice on how i can pull the data from each cell in the column range and enter it into the form?

I'm a little new to this so I apologize for anything ahead of time.

My code:

Sub Test1()

    Dim ie As Object
    Dim doc As HTMLDocument

    Set ie = CreateObject("InternetExplorer.Application")
    saleNum = InputBox("Enter the Sale Address")

    ie.Visible = True
    ie.navigate "WEBSITE" & saleNum

    Do While ie.Busy

        Application.Wait DateAdd("s", 1, Now)

    Loop

    Set doc = ie.document
    doc.getElementById("check_all").Click

    Dim cells As Range
    Dim SalePrice
    Dim Inputs
    Dim PriceRange As Range

    Set SalePrice = doc.getElementsByName("saleprice")
    Set Inputs = doc.getElementsByName("saleprice")

    For Each SalePrice In Inputs

        SalePrice.innerText = ThisWorkbook.Sheets("Prices").Range("A1:A69")

    Next

Upvotes: 2

Views: 613

Answers (2)

K.Dᴀᴠɪs
K.Dᴀᴠɪs

Reputation: 10139

Since you are using two separate collections here (the worksheet range and the saleprice element from the webpage, I would personally prefer an For i = statement rather than a For Each, and you can just loop through each objects collection using their index.

Dim i As Long
With Inputs
    For i = 0 To .Length - 1
        .Item(i).Value = ThisWorkbook.Sheets("Prices").Cells(i + 1, "A")
    Next
End With

Upvotes: 2

QHarr
QHarr

Reputation: 84465

You are currently trying to pass an array rather than a single value during the loop over your input elements. Assuming there are 69 input elements i.e. the number of elements in Inputs is 69, and that your data in sheet is in order you wish to enter, then something like:

Dim i As Long
i = 1
For Each SalePrice In Inputs
    SalePrice.Value = ThisWorkbook.Worksheets("Prices").Range("A" & i).Value
    i = i + 1
Next

Upvotes: 1

Related Questions