Finding the query range

B

Belinda

Hello All

I run a database query from Excel that populates data starting at D11
as follows:

Range("D11").Select
Selection.QueryTable.Refresh BackgroundQuery:=False



Now I want to know what range of cells in the worksheet have been
populated by the query how can we find it ?.

I looked for various functions on the QueryTable I cannot find any
information on how to obtain the Worksheet range that the QueryTable
as populated can you please let me know how I can find the worksheet
range populated by the QueryTable.

Thanks
Belinda
 
T

Tom Ogilvy

range("D11").CurrentRegion

should do it.

but more specifically

Activesheet.queryTables("Table1").ResultRange
 
R

Roger Whitehead

Belinda,

Is this what you mean?

Dim endcell As Range, LastRow As Long, lastColumn As Byte

LastRow =
ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row
lastColumn =
ActiveSheet.UsedRange.Columns(ActiveSheet.UsedRange.Columns.Count).Column

Debug.Print "Querytable Range is " & Range("D11:" & Cells(LastRow,
lastColumn).Address).Address
 

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