ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Do without loop when using query (https://www.excelbanter.com/excel-programming/390905-do-without-loop-when-using-query.html)

[email protected][_2_]

Do without loop when using query
 
I'm stuck:

the following sample code works

----------------------
i = 0
Do Until i = 5
ActiveCell.Offset(0, i) = i
i = i + 1
Loop
-------------------------

Now, the following doesn't and returns a "Do without Loop" error
message

-----------------------
i = 0
Do Until i = 5
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;http://table.finance.yahoo.com/table.csv?s=" & ticker &
i & "&g=d&ignore=.csv", _
Destination:=ActiveCell)
.TextFileCommaDelimiter = True
.TextFileColumnDataTypes = Array(1, 9, 9, 9, 9, 9, 1)
.Refresh BackgroundQuery:=False
ActiveCell.Offset(0, 2).Select
Loop
-----------------------

I've tried with a for/next statement with the same issue.

Any ideas?


PCLIVE

Do without loop when using query
 
You're missing and "End With".

I = 0
Do Until I = 5
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;http://table.finance.yahoo.com/table.csv?s=" & ticker & I
& "&g=d&ignore=.csv", _
Destination:=ActiveCell)
.TextFileCommaDelimiter = True
.TextFileColumnDataTypes = Array(1, 9, 9, 9, 9, 9, 1)
.Refresh BackgroundQuery:=False
End With
ActiveCell.Offset(0, 2).Select
Loop

HTH,
Paul

wrote in message
ups.com...
I'm stuck:

the following sample code works

----------------------
i = 0
Do Until i = 5
ActiveCell.Offset(0, i) = i
i = i + 1
Loop
-------------------------

Now, the following doesn't and returns a "Do without Loop" error
message

-----------------------
i = 0
Do Until i = 5
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;http://table.finance.yahoo.com/table.csv?s=" & ticker &
i & "&g=d&ignore=.csv", _
Destination:=ActiveCell)
.TextFileCommaDelimiter = True
.TextFileColumnDataTypes = Array(1, 9, 9, 9, 9, 9, 1)
.Refresh BackgroundQuery:=False
ActiveCell.Offset(0, 2).Select
Loop
-----------------------

I've tried with a for/next statement with the same issue.

Any ideas?





All times are GMT +1. The time now is 01:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com