PDA

View Full Version : Convert sql to vba code



ThaNguyen
06-05-2008, 09:44 AM
Hi,

I have a spreadsheet that have many tabs aka w1,w2,w3.... and so on. I have a table that queried one of those tab example bottom

SELECT `W48$`.Cost, `W48$`.`Customer Name`, `W48$`.`Customer#`, `W48$`.GP, `W48$`.Margin, `W48$`.Qty, `W48$`.Sales, `W48$`.Wgt, `W48$`.WK
FROM `C:\sales\WK06`.`W48$` `W48$`

Every week I would go into the sql and edit w48 to w49 and so on.

I would like to put this a macro that I could just change the # so I dont have to manually change it every time.

any help would be greatly appreciated

Bob Phillips
06-05-2008, 10:11 AM
Obviously untested



SQLString = "SELECT '" & Range("A1").Value & "$'.Cost, " & _
" '" & Range("A1").Value & "$'.'Customer Name', " & _
" '" & Range("A1").Value & "$'.'Customer#', " & _
" '" & Range("A1").Value & "$'.GP, " & _
" '" & Range("A1").Value & "$'.Margin, " & _
" '" & Range("A1").Value & "$'.Qty, " & _
" '" & Range("A1").Value & "$'.Sales, " & _
" '" & Range("A1").Value & "$'.Wgt, " & _
" '" & Range("A1").Value & "$'.WK" & _
"FROM 'C:\sales\WK06'.'" & Range("A1").Value & "$' '" & Range("A1").Value & "$'"

ThaNguyen
06-05-2008, 10:14 AM
Thank you I will give it a shot and post back with the result.
:yes:yes:yes

ThaNguyen
06-05-2008, 01:54 PM
It works, just have change a couple things but it works.

Thanks again

Bob Phillips
06-05-2008, 02:03 PM
That'sgood, I was guessing a bit as to where your code was at and what you wanted, but the boy done good.