Needing to Loop Data from Excel to Website

Patty28715

New Member
Joined
Feb 19, 2009
Messages
2
I have VBA that pulls datas from cell, inputs into field on website and submits. I then extract data back from website to excel sheet. Right now I'm using a specific cell.

Set HTMLInput = HTMLDoc.getElementById("ssn")
HTMLInput.Value = Sheets(1).Cells(2, 6)


Set HTMLInput = HTMLDoc.getElementById("fName")
HTMLInput.Value = Sheets(1).Cells(2, 4)


Set HTMLInput = HTMLDoc.getElementById("lName")
HTMLInput.Value = Sheets(1).Cells(2, 5)


IE.document.getElementsByName("submit")(0).Click

Adding to specific cell:

ThisWorkbook.Sheets(1).Cells(2, 7) = Mid(Name.innerText, InStr(Name.innerText, "") + 7, 50)
ThisWorkbook.Sheets(1).Cells(2, 8) = Mid(SSN.innerText, 33, 5)
ThisWorkbook.Sheets(1).Cells(2, 9) = Mid(License.innerText, InStr(License.innerText, "") + 30, 50)
ThisWorkbook.Sheets(1).Cells(2, 10) = Mid(Original_Date.innerText, InStr(Original_Date.innerText, "") + 21, 50)
ThisWorkbook.Sheets(1).Cells(2, 11) = Mid(Expiration_Date.innerText, InStr(Expiration_Date.innerText, "") + 26, 50)

I want to loop through the workbook, pull first line of data, extract into excel, go to next row in excel and repeat.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Patty28715,

You might consider the following...

Code:
Dim LastRow As Long, i As Long
LastRow = Sheets(1).Cells(Rows.Count, 6).End(xlUp).Row
For i = 2 To LastRow
    Set HTMLInput = HTMLDoc.getElementById("ssn")
    HTMLInput.Value = Sheets(1).Cells(i, 6)
    
    Set HTMLInput = HTMLDoc.getElementById("fName")
    HTMLInput.Value = Sheets(1).Cells(i, 4)
    
    Set HTMLInput = HTMLDoc.getElementById("lName")
    HTMLInput.Value = Sheets(1).Cells(i, 5)
    
    IE.document.getElementsByName("submit")(0).Click
    Do Until IE.readystate = 4
        DoEvents
    Loop
    
    'Adding to specific cell:
    ThisWorkbook.Sheets(1).Cells(i, 7) = Mid(Name.innerText, InStr(Name.innerText, "") + 7, 50)
    ThisWorkbook.Sheets(1).Cells(i, 8) = Mid(SSN.innerText, 33, 5)
    ThisWorkbook.Sheets(1).Cells(i, 9) = Mid(License.innerText, InStr(License.innerText, "") + 30, 50)
    ThisWorkbook.Sheets(1).Cells(i, 10) = Mid(Original_Date.innerText, InStr(Original_Date.innerText, "") + 21, 50)
    ThisWorkbook.Sheets(1).Cells(i, 11) = Mid(Expiration_Date.innerText, InStr(Expiration_Date.innerText, "") + 26, 50)
Next i

Please note the code is untested.

Cheers,

tonyyy
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,334
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top