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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
put 00:15 in say Z1 and make it interval.Offset(i, 0) = interval.Offset(i, 0) + cells(1,26)
 
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
 
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,215,691
Messages
6,126,219
Members
449,303
Latest member
grantrob

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