Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loop through a decimal sequence

Tags:

excel

vba

I am writing a loop in VBA for excel, and I would like to loop through a sequence of decimal numbers, rather than integers.

For example:

For i = 1 To 10
    'Do something
Next i

But rather than incrementibg by 1, I would like to increment by 0.5 (or perhaps 5, or really any number other than 1).

like image 929
Zach Avatar asked Mar 18 '26 19:03

Zach


1 Answers

Dim i as Single

For i = 1 To 10 Step 0.5
    '
Next

But note you can get some unwanted numbers because of the floating numbers not being precise.

like image 103
GSerg Avatar answered Mar 21 '26 10:03

GSerg