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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
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,214,614
Messages
6,120,525
Members
448,969
Latest member
mirek8991

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