Automating an Internet Explorer process by using VBA Excel.
I am trying to get the first link in this classname 'datacell' with the th scope=row in html using the first 'a href' tag as my needed link.
Correct link is black circled but the result is the red circled one

VBA code:
Set appIE = New InternetExplorerMedium
With appIE
.Visible = False
.Visible = True
Set doc = appIE.document
For Each li In doc.getElementsByClassName("list")
checkIfAttachment = li.innerHTML
If InStr(checkIfAttachment, "No matches found") Then
ws.Cells(i, 6).Value = "Not in SFDC"
Else
Set childLi = Nothing
For Each childLi In doc.getElementsByClassName(" dataCell ")
link = childLi.getElementsByTagName("a")(0)
'first link is the one we want
Next childLi
link = Replace(link, "https://sample.com", "")
link = Replace(link, "?srPos=0&srKp=00P", "")
.navigate baseSFDCDownloadLink & link
Do While .Busy = True Or .readyState <> 4: DoEvents: Loop
Application.Wait (Now + TimeValue("0:00:05"))
<>which will allow you to insert and format html.