Question : I'm able to iterate through every row of the table using Cells property but getting Run Time Error 91
End Result : Fix the Error
Code
Sub GetData()
Dim IE As SHDocVw.InternetExplorer
Dim FIUrl As MSHTML.HTMLDocument
Dim Url As String
Dim d1, e1, f1, Counter, Counter1, Counter2, Counter6 As Long
Dim BSMCTable As IHTMLTable
Dim BSMCTableRowCollection As IHTMLElementCollection
Dim BSMCHeaderObj As IHTMLTableRow
Dim BSMCRowObj As IHTMLTableRow
Dim BSMCHeaderCellObj As IHTMLTableCell
Dim BSMCRowCellObj As IHTMLTableCell
Dim BSMCRowNameCellObj As IHTMLTableCell
Set IE = New SHDocVw.InternetExplorerMedium
Url = "http://www.moneycontrol.com/financials/bombayburmahtradingcorporation/balance-sheetVI/BBT#BBT"
IE.Navigate Url
IE.Visible = True
Do While IE.ReadyState <> READYSTATE_COMPLETE
Loop
Set FIUrl = IE.Document
If FIUrl.ReadyState = "complete" Then
Set BSMCTable = FIUrl.getElementsByTagName("table").Item(4)
Set BSMCTableRowCollection = FIUrl.getElementsByTagName("table").Item(4).getElementsByTagName("tr")
Debug.Print BSMCTableRowCollection.Length
Set BSMCHeaderObj = BSMCTable.Rows(0)
For d1 = 1 To BSMCTableRowCollection.Length
Set BSMCRowObj = BSMCTable.Rows(d1)
I'm getting [B]Error[/B] on the line, [B]below[/B] :
Set BSMCRowNameCellObj = BSMCRowObj.[B]Cells[/B](0)
Debug.Print BSMCRowNameCellObj.innerText
If (BSMCRowNameCellObj.innerText = "Trade Payables") Then
Counter = 53
If (BSMCRowNameCellObj.innerText = Range("B" & Counter).Value) Then
Counter1 = 5
For e1 = 5 To 1 Step -1
Counter1 = Counter1 + 1
Set BSMCHeaderCellObj = BSMCHeaderObj.Cells(e1)
Set BSMCRowCellObj = BSMCRowObj.Cells(e1)
Debug.Print BSMCHeaderCellObj.innerText & " " & BSMCRowCellObj.innerText & " " & Counter1
Next
End If
ElseIf (BSMCRowNameCellObj.innerText = "Other Current Liabilities") Then
Counter6 = 55
If (BSMCRowNameCellObj.innerText = Range("B" & Counter6).Value) Then
Counter2 = 5
For f1 = 5 To 1 Step -1
Counter2 = Counter2 + 1
Set BSMCHeaderCellObj = BSMCHeaderObj.Cells(f1)
Set BSMCRowCellObj = BSMCRowObj.Cells(f1)
Debug.Print BSMCHeaderCellObj.innerText & " " & BSMCRowCellObj.innerText & " " & Counter2
Next
End If
End If
Next
End If
End Sub
Display More