Splitting daily figure into 48 periods

Woofy_McWoof_Woof

Board Regular
Joined
Oct 7, 2016
Messages
60
Office Version
  1. 365
Platform
  1. Windows
Hi, I have thecode below which splits 24 hourly prices into 48 half hourly periods. Iwould like to do something similar whereby I take a daily figure and split thisinto 48 half hourly periods. I have tried altering it in different ways but nosuccess. Any ideas? Thanks for your help.
Column A = Date
Column B = Period
Column C = Price


Sub Split_Periods_v2()
Dim a As Variant, b As Variant
Dim i As Long, p As Long

a = Range("A2", Range("C" & Rows.Count).End(xlUp)).Value
ReDim b(1 To 2 * UBound(a), 1 To 3)
For i = 1 To UBound(a)
b(i * 2 - 1, 1) = a(i, 1): b(i * 2 - 1, 2) = i * 2 - 1 - p: b(i * 2 - 1, 3) = a(i, 3)
b(i * 2, 1) = a(i, 1): b(i * 2, 2) = i * 2 - p: b(i * 2, 3) = a(i, 3)
If i Mod 24 = 0 Then p = i * 2
Next i
Range("D2").Resize(UBound(b), 3).Value = b
Range("D1:F1").Value = Array("Date", "Period", "N2EX")
End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Lacking an examples of valid input data and their desired output, I made a best guess of what I believe you wanted:

Code:
Sub Split_Periods_v2()
    'For each data set in columns A:C, starting in row 2
    'A = Date
    'B = Period (ignored)
    'C = Amount
    'Replicate each row's data 48 times in column D:F with
    '  column E repeating counts from 1 to 48
    

    Dim a As Variant, b As Variant
    Dim lbIndex As Long, p As Long
    Dim lSplitIndex As Long
    
    a = Range("A2", Range("C" & Rows.Count).End(xlUp)).Value
    
    ReDim b(1 To 48 * UBound(a), 1 To 3)
    
    For lbIndex = 1 To UBound(a)
        For lSplitIndex = 1 To 48
            b((lbIndex - 1) * 48 + lSplitIndex, 1) = a(lbIndex, 1)
            b((lbIndex - 1) * 48 + lSplitIndex, 2) = lSplitIndex
            b((lbIndex - 1) * 48 + lSplitIndex, 3) = a(lbIndex, 3)
        Next lSplitIndex
    Next lbIndex
    Range("D2").Resize(UBound(b), 3).Value = b
    Range("D1:F1").Value = Array("Date", "Period", "N2EX")
    
End Sub
 
Upvote 0
My word that is impressive, it works a treat.

PS: sorry for the late reply, I was on my jolly holibobs
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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