John Garabiles John Garabiles - 10 months ago 37
SQL Question

Excel VBA - how to display the SQL results on a specific cell?

With ActiveSheet.QueryTables.Add(Connection:.., Destination:=Range("A1"))

so instead the sql results will display starting in A1, i would like to specify it depending on what the value inside the cell B1 for example

i tried this:

With ActiveSheet.QueryTables.Add(Connection:..,Destination:=Range("A1").value)

but its not working.


That's because Range("A1").value is returning a String containing "B1" instead of a Range object representing the B1 position.

Try this instead: ActiveSheet.QueryTables.Add(Connection:..,Destination:=Range(Range("A1").value))