Macro to Loop through a list of numbers including decimals

BradMS

New Member
Joined
Jan 27, 2017
Messages
32
HI, I would like to have my macro loop through a list on sheet LoopList from a1 to a450

a1=15
a2=15.1
a3=15.2
etc.....

my loop will be changing a website address (which has the data) by my LoopList #'s

I have tried

************************

For i = 15.1 To 18 Step 0.1

With Worksheets("Temp").QueryTables.Add(Connection:= _
"URL;http://www.websitehere" & i & "the rest of the website here.com" _
, Destination:=Worksheets("Temp").Range("$A$" & lastRow))
.Name = "table"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.WebSelectionType = "1"
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = True
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With

*modifications to the sheet


next i

***************************


This will not place a decimal in my i (or my website address)

So I figured, i should have a list and it to grab specific numbers from there. I do not know how to go about doing this.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
What is i defined as? An integer? Integers have no decimals.

Try
Dim i as integer
For i = 151 to 180
use i/10 in place of i (in your current code)
 
Upvote 0
What is i defined as? An integer? Integers have no decimals.

Try
Dim i as integer
For i = 151 to 180
use i/10 in place of i (in your current code)
Since the code deals with decimal values, I believe the OP would want to Dim i As Double. The problem is that the loop will have ten iterations per whole number 1 units. Or in this case, about 32 iterations. That might be what the OP wants.
 
Last edited:
Upvote 0
Since the code deals with decimal values, I believe the OP would want to Dim i As Double. The problem is that the loop will have ten iterations per whole number 1 units. Or in this case, about 32 iterations. That might be what the OP wants.

Thanks. Changing to Double worked!
 
Upvote 0

Forum statistics

Threads
1,215,352
Messages
6,124,449
Members
449,160
Latest member
nikijon

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