How to insert required rows for a dynamic SQL in VBA

mblake5

New Member
Joined
May 24, 2012
Messages
18
I have a working dynamic SQL in a VBA-macro. The only problem I'm having is how to insert the required number of rows. At the moment, if there is anything in the first row it needs, it inserts the entire table to the left (which I don't want). I'd rather it overwrite what is there. If nothing is in the first row, it creates the table and overwrites everything to do it. Is there a way to declare a row for the table that it will expand/diminish as needed? Basically, I want it to populate as a regular SQL database query outside of VBA.

Currently I have this to update the table:

Set oQt = ActiveSheet.QueryTables.Add( _
Connection:=sConn, _
Destination:=Range("a3"), _
Sql:=var1)
oQt.Refresh
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,203,171
Messages
6,053,876
Members
444,692
Latest member
Queendom

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