Convert 30 min interval data to 5 min intervals

MAP77

Board Regular
Joined
Sep 19, 2018
Messages
60
Office Version
  1. 365
Platform
  1. Windows
Hi guys!
I have 30-minute interval data for the whole month of April that needs to be converted into 5-minute intervals. Eg. The value in B1 needs to be divided by 6 and put into column F1:F6, and the value in B2 needs to be divided by 6 and put in F7:F12. Is this able to be done in Excel? If so, how? Or is it something that could be done quicker in power query?

PQ april conversion to 5 min.xlsx
E
51/04/2023 0:20
Sheet1
Cell Formulas
RangeFormula
E5E5=E4+TIME(0,5,0)
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
The definition of the problem is weak, thus maybe this solution will not work for you, but try the following macro:
Code:
Sub Step5()
Dim I As Long, J As Long, FI As Long, FMins As Double
Dim Dest0 As Range
'
Set Dest0 = Range("F1")             '<<< Where the 5 minutes list will start from
FMins = TimeSerial(0, 5, 0)
On Error GoTo GErr
For I = 1 To Cells(Rows.Count, "B").End(xlUp).Row
    If IsDate(Cells(I, "B")) Then
        For J = 0 To 5
            FI = FI + 1
            Dest0.Cells(FI, 1).Value = Cells(I, "B").Value + J * FMins
        Next J
    Else
        Dest0.Cells(FI + 1, 1).Resize(6, 1).ClearContents
        FI = FI + 6
    End If
Next I
Beep
Exit Sub
'
GErr:
Debug.Print Now
Debug.Print "A:", I, J, FI
Debug.Print "B:", Cells(I, 2).Value, TypeName(Cells(I, 2).Value)
MsgBox ("Error processing line " & I & vbCrLf & "Process aborted")
End Sub
Copy the code into a "Standard Module" of your vba; the line marked <<< let you specify the starting address of the output list.
Then select the worksheet with your data and excecute Sub Step5
A "beep" will advice the macro has completed without error; or a msgbox will report on which line of column B the process has been halted

Try...
 
Upvote 0
The definition of the problem is weak, thus maybe this solution will not work for you, but try the following macro:
Code:
Sub Step5()
Dim I As Long, J As Long, FI As Long, FMins As Double
Dim Dest0 As Range
'
Set Dest0 = Range("F1")             '<<< Where the 5 minutes list will start from
FMins = TimeSerial(0, 5, 0)
On Error GoTo GErr
For I = 1 To Cells(Rows.Count, "B").End(xlUp).Row
    If IsDate(Cells(I, "B")) Then
        For J = 0 To 5
            FI = FI + 1
            Dest0.Cells(FI, 1).Value = Cells(I, "B").Value + J * FMins
        Next J
    Else
        Dest0.Cells(FI + 1, 1).Resize(6, 1).ClearContents
        FI = FI + 6
    End If
Next I
Beep
Exit Sub
'
GErr:
Debug.Print Now
Debug.Print "A:", I, J, FI
Debug.Print "B:", Cells(I, 2).Value, TypeName(Cells(I, 2).Value)
MsgBox ("Error processing line " & I & vbCrLf & "Process aborted")
End Sub
Copy the code into a "Standard Module" of your vba; the line marked <<< let you specify the starting address of the output list.
Then select the worksheet with your data and excecute Sub Step5
A "beep" will advice the macro has completed without error; or a msgbox will report on which line of column B the process has been halted

Try...
Hi Anthony,
Thanks for this. I ran the macro, and it beeped, but nothing happened. I changed the Range from ("F1") to ("F1:F8640") but everything else was the same. Sorry, I'm not very familiar with macros but no error came up.
 
Upvote 0
Can you show the content of say B1:B5, using XL2BB?
Can you tell me the name of the vba module where the code has been inserted (look into the head of the vba window)
Also, if you format B1 as "Number with two decimals", how the cell is displayed?
If you wish to create the list starting from F1 then leave Set Dest0 = Range("F1")
 
Last edited:
Upvote 0
Sorry, I only just realised I didn't copy the file properly.

PQ april conversion to 5 min.xlsm
ABCDE
11/04/2023 0:007.811/04/2023 0:00
21/04/2023 0:307.781/04/2023 0:05
31/04/2023 1:008.251/04/2023 0:10
41/04/2023 1:307.251/04/2023 0:15
51/04/2023 2:007.271/04/2023 0:20
61/04/2023 2:306.331/04/2023 0:25
71/04/2023 3:007.381/04/2023 0:30
81/04/2023 3:308.221/04/2023 0:35
91/04/2023 4:007.751/04/2023 0:40
101/04/2023 4:309.541/04/2023 0:45
111/04/2023 5:007.991/04/2023 0:50
121/04/2023 5:308.061/04/2023 0:55
131/04/2023 6:007.971/04/2023 1:00
141/04/2023 6:308.411/04/2023 1:05
151/04/2023 7:009.021/04/2023 1:10
161/04/2023 7:309.41/04/2023 1:15
171/04/2023 8:008.981/04/2023 1:20
181/04/2023 8:3012.21/04/2023 1:25
191/04/2023 9:0012.771/04/2023 1:30
201/04/2023 9:3012.651/04/2023 1:35
Sheet1
Cell Formulas
RangeFormula
E2:E20E2=E1+TIME(0,5,0)
 
Upvote 0
Reminder:
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Excel Forum
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
In your first message you wrote that the dates to convert are in column B, but from your minisheet they seem to be in column A.
In this case you need to adapt the macro for column A:
VBA Code:
Sub Step5()
Dim I As Long, J As Long, FI As Long, FMins As Double
Dim Dest0 As Range
'
Set Dest0 = Range("F1")             '<<< Where the 5 minutes list will start from
FMins = TimeSerial(0, 5, 0)
On Error GoTo GErr
For I = 1 To Cells(Rows.Count, "A").End(xlUp).Row
'    Debug.Print I, TypeName(Cells(I, "A").Value), Cells(I, "A").Value
    If IsDate(Cells(I, "B")) Then
        For J = 0 To 5
            FI = FI + 1
            Dest0.Cells(FI, 1).Value = Cells(I, "A").Value + J * FMins
        Next J
    Else
        Dest0.Cells(FI + 1, 1).Resize(6, 1).ClearContents
        FI = FI + 6
    End If
Next I
Exit Sub
'
GErr:
Debug.Print Now
Debug.Print "A:", I, J, FI
Debug.Print "B:", Cells(I, 1).Value, TypeName(Cells(I, 1).Value)
MsgBox ("Error processing line " & I & vbCrLf & "Process aborted")
End Sub
 
Upvote 0
Sorry for the confusion, I didn't realise you couldn't see the file. As you can see, I have already converted the dates. What I needed help with was taking the 30 min value in B1, dividing it by 6 to give me a 5 min interval value to go in column F.
 
Upvote 0
Reminder:
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Excel Forum
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
I didn't realise that the other place I posted the question was related to this forum. I posted it in the other area because that's where I did my Excel course and Mynda had helped me with a similar problem.
 
Upvote 0

Forum statistics

Threads
1,215,076
Messages
6,122,987
Members
449,093
Latest member
Mr Hughes

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