Change 15 Minutes into 30 Minutes Intervals VBA

kamiljaku

New Member
Joined
Jan 5, 2018
Messages
21
Im struggeling with a macro which needs to convert 15 min intervals to 30 min

Original data looks like

00:00235
00:15214
00:30526
00:45534
01:00742
01:15723

<tbody>
</tbody>


and I would need such an outcome somewhere right or left from the original

00:00449
00:3010510
01:001465

<tbody>
</tbody>



This is how far I have come

Sub IEX2()


Dim m As Integer
Dim i As Integer




For m = 1 To 10
Cells(m, 2).Value = WorksheetFunction.Sum(Cells(m * 2 - 1, 1).Resize(2))
Next


End Sub


It works even but I need to loop it somehow so it converts all coming columns and not just one. Could someone help?
 
Last edited:

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
How about
Code:
Sub IEX2()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long, c As Long, i As Long
   
   Ary = Range("A1").CurrentRegion.value2
   ReDim Nary(1 To UBound(Ary), 1 To UBound(Ary, 2))
   For r = 1 To UBound(Ary) Step 2
      i = i + 1
      Nary(i, 1) = Ary(r, 1)
      For c = 2 To UBound(Ary, 2)
         Nary(i, c) = Ary(r, c) + Ary(r + 1, c)
      Next c
   Next r
   Range("A1").CurrentRegion.ClearContents
   Range("A1").Resize(i, UBound(Ary, 2)).Value = Nary
End Sub
 
Upvote 0
Couldn't you use a simple SUMIFS formula?

For example with 00:00, 00:30 etc. in column H and the original data in A1:D6.

=SUMIFS(B$1:B$6,$A$1:$A$6,">="&$H1,$A$1:$A$6, "<"&$H1+TIME(0,30,0))
 
Upvote 0
How about
Code:
Sub IEX2()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long, c As Long, i As Long
   
   Ary = Range("A1").CurrentRegion.value2
   ReDim Nary(1 To UBound(Ary), 1 To UBound(Ary, 2))
   For r = 1 To UBound(Ary) Step 2
      i = i + 1
      Nary(i, 1) = Ary(r, 1)
      For c = 2 To UBound(Ary, 2)
         Nary(i, c) = Ary(r, c) + Ary(r + 1, c)
      Next c
   Next r
   Range("A1").CurrentRegion.ClearContents
   Range("A1").Resize(i, UBound(Ary, 2)).Value = Nary
End Sub


Works like a dream. Now I just need to figure out how this is actually working as Im a beginner :)
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
Couldn't you use a simple SUMIFS formula?

For example with 00:00, 00:30 etc. in column H and the original data in A1:D6.

=SUMIFS(B$1:B$6,$A$1:$A$6,">="&$H1,$A$1:$A$6, "<"&$H1+TIME(0,30,0))


I could and I have worked out my own formula to do this

index(B$5:B$100,rows(B$5:B8)*2)+index(B$4:B$99,rows(B$4:B7)*2)

but I've needed it in VBA because it is just a part of a bigger macro. Although thanks for your tip, I will go trough your formula as it seems pretty simple.
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,175
Members
449,071
Latest member
cdnMech

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