VBA SQL Query from Cell

LePig

New Member
Joined
Aug 30, 2016
Messages
16
Hi I am trying to get data from a cell and need a little help.

Code:
sSQLSting = "SELECT * From (" & Sheets(SpreadsheetName).Cells(firstAddress, Colname + 2) & ")"

This is returning nothing?

Any help would be appreciated.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
What are your values of the SpreadsheetName, firstAddress, and Colname variables?

I would recommend using a MsgBox to see what it is returning, i.e.
Code:
MsgBox sSQLSting
and inspect it to see if it looks correct.

By the way, perhaps you have a typo. Note that you have sSQLSting and and not sSQLString.
You didn't post how you were using/calling this string, so we cannot verify that for you.
 
Upvote 0

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation:
Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.

Please be sure to do this going forward.
 
Last edited:
Upvote 0
I have a msgbox and it is returning the following

SELECT * FROM (451)

but then i get a run time error, cannot find object 451
Surely, the name of your table isn't (451), is it?
What is the name of the table you are trying to pull data from?
 
Upvote 0
They why use SQL at all?

Maybe just something like:
Code:
MsgBox Sheets(SpreadsheetName).Cells(firstAddress, Colname + 2).Value
 
Upvote 0
I have done that - I am using SQL because lots of people are going to accessing the file so thought a database approach would be better
 
Upvote 0
So where exactly are you trying to run this code from?
Excel VBA, a SQL View, a SQL stored procedure?
 
Upvote 0

Forum statistics

Threads
1,215,492
Messages
6,125,116
Members
449,206
Latest member
burgsrus

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