How to obtain the row count of a QueryTable from a Web query

F

Felix_Jiang

I use a Web query to obtain a table on a Web page. How can I know the number
of rows in the result QueryTable?

The current code I use is as follows:

Sub Test()
Dim MyStr As String
MyStr = "URL;http://mySite/currentuser"
With ActiveSheet.QueryTables.Add(Connection:=MyStr, _
Destination:=Range("a10"))

.RowNumbers = True
.WebSelectionType = xlSpecifiedTables
.WebTables = "11"
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.SaveData = True
End With


End Sub
 
D

Don Guillett

?? Maybe something as simple as
msgbox cells(rows.count,"a").end(xlup).row
 
F

Felix_Jiang

Thank you Sanjay. I want to know the row count in the QueryTable returned by
ActiveSheet.QueryTables.Add. Then after I put the QueryTable into Excel, I
can calculate the last affected row in Excel. This will help me to know where
to start adding new QueryTable.
 
F

Felix_Jiang

I found the answer. The row count can be obtained by using
QueryTable.ResultRange.Rows.Count
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top