I have the following VBA code that allows me to populate fields in an Intranet site on Internet Explorer from Excel rows in my file, but now I want to know if there was a method to loop to the last row not empty without manually repeating the lines here is the code:
`Sub template()
Application.DisplayAlerts = False
Application.WindowState = xlMinimized
On Error Resume Next
Dim objApp
Dim objIE
Dim objWindow
Dim ie As Object
Dim strURL
Set ie = CreateObject("InternetExplorer.Application")
Set objApp = CreateObject("Shell.Application")
Set objIE = Nothing
strURL = "http://Intranet"
For Each objWindow In objApp.Windows
If (InStr(objWindow.Name, "Internet Explorer")) Then
If (objWindow.LocationURL = strURL) Then
Set objIE = objWindow
Exit For
End If
End If
Next
If (objIE Is Nothing) Then
Set objIE = CreateObject("InternetExplorer.Application")
objIE.navigate (strURL)
End If
With objIE
.Visible = True
Do While .Busy Or .readyState <> 4
Loop
Do While .document.readyState <> "complete"
Loop
**the first line:**
.document.getelementbyID("inputND").Value = Worksheets("Feuil1").Range("A2")
.document.getelementbyID("inputND").innerText = Worksheets("Feuil1").Range("A2")
.document.getElementsByTagName("button")(1).Click
Application.Wait Now + TimeValue("00:00:01")
.document.getelementbyID("categorisation_1").Value = Worksheets("Feuil1").Range("B2") & ": Object" '.Value = ": Object"
Application.Wait Now + TimeValue("00:00:01")
.document.getelementbyID("categorisation_2").Value = Worksheets("Feuil1").Range("D2") & ": Object"
Application.Wait Now + TimeValue("00:00:01")
.document.getelementbyID("categorisation_3").Value = Worksheets("Feuil1").Range("F2") & ": Object"
Application.Wait Now + TimeValue("00:00:01")
MsgBox "Please check before continuing", vbMsgBoxSetForeground + vbSystemModal
**the second line:**
.document.getelementbyID("link61").Click
.navigate "http://Intranet"
Application.Wait Now + TimeValue("00:00:01")
.document.getelementbyID("inputND").Value = Worksheets("Feuil1").Range("A3")
.document.getelementbyID("inputND").innerText = Worksheets("Feuil1").Range("A3")
.document.getElementsByTagName("button")(1).Click
Application.Wait Now + TimeValue("00:00:01")
.document.getelementbyID("categorisation_1").Value = Worksheets("Feuil1").Range("B3") & ": Object" '.Value = ": Object"
Application.Wait Now + TimeValue("00:00:01")
.document.getelementbyID("categorisation_2").Value = Worksheets("Feuil1").Range("D3") & ": Object"
Application.Wait Now + TimeValue("00:00:01")
.document.getelementbyID("categorisation_3").Value = Worksheets("Feuil1").Range("F3") & ": Object"
Application.Wait Now + TimeValue("00:00:01")
MsgBox "Please check before continuing", vbMsgBoxSetForeground + vbSystemModal
.document.getelementbyID("link61").Click
**the third line:**
'........................
End With
Application.DisplayAlerts = True
End Sub`
the first line: Worksheets("Feuil1").Range("A2");Worksheets("Feuil1").Range("B2");Worksheets("Feuil1").Range("D2");Worksheets("Feuil1").Range("F2")
the second line: Worksheets("Feuil1").Range("A3");Worksheets("Feuil1").Range("B3");Worksheets("Feuil1").Range("D3");Worksheets("Feuil1").Range("F3")
the third line: Worksheets("Feuil1").Range("A4");Worksheets("Feuil1").Range("B4");Worksheets("Feuil1").Range("D4");Worksheets("Feuil1").Range("F4")
and so on until the last non-empty line.
i don't want the following part of the code to repeat each time after the MsgBox i want the code to go in the second line on sheet1 and so on until the last non-empty line
.document.getelementbyID("inputND").Value = Worksheets("Feuil1").Range("A2")
.document.getelementbyID("inputND").innerText = Worksheets("Feuil1").Range("A2")
.document.getElementsByTagName("button")(1).Click
Application.Wait Now + TimeValue("00:00:01")
.document.getelementbyID("categorisation_1").Value = Worksheets("Feuil1").Range("B2") & ": Object" '.Value = ": Object"
Application.Wait Now + TimeValue("00:00:01")
.document.getelementbyID("categorisation_2").Value = Worksheets("Feuil1").Range("D2") & ": Object"
Application.Wait Now + TimeValue("00:00:01")
.document.getelementbyID("categorisation_3").Value = Worksheets("Feuil1").Range("F2") & ": Object"
Application.Wait Now + TimeValue("00:00:01")
MsgBox "Please check before continuing", vbMsgBoxSetForeground + vbSystemModal
I hope to be clearer now but if you have any questions ask the months and thank you