Column added when Querytables.add in a loop

B

Ben

Hi,
each time the row is change(R=R+1) a new query is created. But the
problem is with the result s destination. Except for the first time datas are
inserted, each time datas are inserted in Range("K" & R & ""), it creates a
new column.
Go figure!

Thank you

Do Until Cells(R, 5) = "TOTAL:"

R = 8
FrstDay = 7
LastDay = 14
Card1 = Cells(R, 4)
Sqlstring = "select sum(Temps_Arrondi) from Presence_BCV_App where
Card= '" & Card1 & "' and ([Date] > '" & FrstDay & "' and [Date] < '" &
LastDay & "') "
connstring = "ODBC;DSN=DEV_DCI;UID=sa;PWD=abcde;Database=DEV_DCI"

With
ActiveSheet.QueryTables.Add(Connection:=connstring,Destination:=Range("K" &
R),Sql:=sqlstring)
.Refresh BackgroundQuery = False
End With

R = R + 1
Loop
 
G

George Nicholson

each time the row is change(R=R+1) a new query is created

except that you reset R = 8 at the top of your loop, so I don't see how a
"new row" is ever created. As far as I can see, you are always using the
same cell (K8) as a destination. At least, according to the code you
provided.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top