Loop+ Offset issue

kamiljaku

New Member
Joined
Jan 5, 2018
Messages
21
Hey,

what is wrong in the code below. I need to receive a output like

00:00
00:15
00:30
00:45

but instead d I get

00:00
00:15
00:15
00:15


----------------------------------------------------

Dim interval As Range
Range("E6").Value = "00:00"
Set interval = Range("E6")


For i = 1 To 95
interval.Offset(i, 0) = interval.Offset(i, 0) + "00:15"
Next i
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Two things:
You are not adding to the previous value, but the current value in your formula.
Add time, not a string. One hour is equal to 1/24. So 15 minutes is equal to 1/96.
This is because date/time is store as integers in Excel, specifically the number of days since 1/0/1900. So one day = 1, and hours are a fraction of one day.

So try this:
Code:
Dim interval As Range
Range("E6").Value = "00:00"
Set interval = Range("E6")


For i = 1 To 95
    interval.Offset(i, 0) = [COLOR=#ff0000]interval.Offset(i - 1, 0) + 1 / 96[/COLOR]
Next i
 
Upvote 0
Two things:
You are not adding to the previous value, but the current value in your formula.
Add time, not a string. One hour is equal to 1/24. So 15 minutes is equal to 1/96.
This is because date/time is store as integers in Excel, specifically the number of days since 1/0/1900. So one day = 1, and hours are a fraction of one day.

So try this:
Code:
Dim interval As Range
Range("E6").Value = "00:00"
Set interval = Range("E6")


For i = 1 To 95
    interval.Offset(i, 0) = [COLOR=#ff0000]interval.Offset(i - 1, 0) + 1 / 96[/COLOR]
Next i

Thank you it worked and I understood the explanation :) very greatful
 
Upvote 0
You are welcome.
Glad I was able to help!
:)
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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