VBA query on external worksheet to an array

Peanuts890

New Member
Joined
Aug 3, 2011
Messages
4
:)Can the results of a Microsoft query on an external worksheet be routed to an array instead of a worksheet. I have already tried doing a query on an external worksheet, selecting 8 out od 10 columns and filtering the rows by a specific value in one of the cells. This was successful with the results going to a worksheet. Noted however that the query didn't recognise the header row in the external worksheet and the results had a first row like a filter.
Hope to be able to develop a macro to do the query, then do further manipulation on the array before displaying results in a worksheet.
Any help on this would be gratefully appreciated - bit of a novice on macros/VBA -many thanks.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
No, I don't think you can assign the results of a query directly to an array; the Destination property must be a range. You could copy the range results to an array, like this:
Code:
    Dim theArray As Variant
    Dim query As QueryTable
    Dim resRange As Range
    
    Set resRange = query.ResultRange
       
    'The whole result range
    theArray = resRange.Value
    
    'With row 1 omitted
    theArray = resRange.Offset(1, 0).Resize(resRange.Rows.Count - 1, resRange.Columns.Count).Value
The query variable is your Microsoft query, however you've set that up.
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top