Splitting Data into Monthly Based on Date Range

kingspur06

Board Regular
Joined
Apr 24, 2007
Messages
50
Hi - I have a question relating to the attached thread


I know nothing about VBA so have been trying to update the code that was suggested on that thread to fit my data.
My ID is in Col A
My Start Date is Col L, End Date is Col M, Total Days is Col N.
I then have 8 separate Total Values from Cols R-Y and calculated Daily Values from Cols Z-AG.

So using the attached code, I tweaked it to this.....

Sub SplitBookings()
Dim r As Long

Application.ScreenUpdating = False
r = 2
While Cells(r, "A") <> ""
If Cells(r, "M") > WorksheetFunction.EoMonth(Cells(r, "L"), 0) + 1 Then
Rows(r + 1).Insert
Rows(r).Copy Rows(r + 1)
Cells(r, "M") = WorksheetFunction.EoMonth(Cells(r, "L"), 0) + 1
Cells(r + 1, "L") = Cells(r, "M")
Cells(r, "N") = Cells(r, "M") - Cells(r, "L")
Cells(r, "R") = Cells(r, "N") * Cells(r, "Z")
Cells(r, "S") = Cells(r, "N") * Cells(r, "AA")
Cells(r, "T") = Cells(r, "N") * Cells(r, "AB")
Cells(r, "U") = Cells(r, "N") * Cells(r, "AC")
Cells(r, "V") = Cells(r, "N") * Cells(r, "AD")
Cells(r, "W") = Cells(r, "N") * Cells(r, "AE")
Cells(r, "X") = Cells(r, "N") * Cells(r, "AF")
Cells(r, "Y") = Cells(r, "N") * Cells(r, "AG")
Cells(r + 1, "N") = Cells(r + 1, "M") - Cells(r + 1, "L")
Cells(r + 1, "R") = Cells(r + 1, "H") * Cells(r + 1, "Z")
Cells(r + 1, "S") = Cells(r + 1, "H") * Cells(r + 1, "AA")
Cells(r + 1, "T") = Cells(r + 1, "H") * Cells(r + 1, "AB")
Cells(r + 1, "U") = Cells(r + 1, "H") * Cells(r + 1, "AC")
Cells(r + 1, "V") = Cells(r + 1, "H") * Cells(r + 1, "AD")
Cells(r + 1, "W") = Cells(r + 1, "H") * Cells(r + 1, "AE")
Cells(r + 1, "X") = Cells(r + 1, "H") * Cells(r + 1, "AF")
Cells(r + 1, "Y") = Cells(r + 1, "H") * Cells(r + 1, "AG")
End If
r = r + 1
Wend
Application.ScreenUpdating = True

End Sub


However I get a Run-time error '13': Type mismatch when I try to run it.

Wondered if there is anybody that actually knows VBA that could let me know what I have done wrong?
many thanks
Mark
 
If you want to copy/paste values in columns Z-AG at the start, you can add a block like this to the top of the code (before your loop):
VBA Code:
    Dim lr As Long
    
'   Find last row with data in column Z
    lr = Cells(Rows.Count, "Z").End(xlUp).Row
    
'   Turn all the formulas into values for columns Z-AG
    Range("Z2:AG" & lr).Value = Range("Z2:AG" & lr).Value
 
Upvote 0
Solution

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
If you want to copy/paste values in columns Z-AG at the start, you can add a block like this to the top of the code (before your loop):
VBA Code:
    Dim lr As Long
   
'   Find last row with data in column Z
    lr = Cells(Rows.Count, "Z").End(xlUp).Row
   
'   Turn all the formulas into values for columns Z-AG
    Range("Z2:AG" & lr).Value = Range("Z2:AG" & lr).Value
perfect - many thanks
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,917
Members
449,093
Latest member
dbomb1414

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