irfananeeza
Active Member
- Joined
- Feb 15, 2008
- Messages
- 339
- Office Version
- 2010
Hi Experts,
After spending couple hours on google I decided to ask for help. I have created a vba code which (A) converts date text to column (B) Sort the data by month (C) Checks If current month different from previous month (D) When months are different, Insert an entire row few times (E) Also, add titles to each separated month.
When data is separated into months, I want to SUM TOTAL each month but I am unable to figure it out. In brief, I'd like to see monthly sum in Column B next to "Total" in Column A. I would appreciate your help. Here is my VBA Code. Thanks.
After spending couple hours on google I decided to ask for help. I have created a vba code which (A) converts date text to column (B) Sort the data by month (C) Checks If current month different from previous month (D) When months are different, Insert an entire row few times (E) Also, add titles to each separated month.
When data is separated into months, I want to SUM TOTAL each month but I am unable to figure it out. In brief, I'd like to see monthly sum in Column B next to "Total" in Column A. I would appreciate your help. Here is my VBA Code. Thanks.
VBA Code:
Sub Macro4()
Dim lastrw As Integer
Dim ChkRw As Integer
lastrw = Range("A" & Rows.Count).End(xlUp).Row
Columns("A:A").TextToColumns Destination:=Range("A1")
Range("A1:C" & lastrw).SORT Key1:=Range("A1")
For ChkRw = lastrw To 1 Step -1
If Left(Range("A" & ChkRw), 2) <> Left(Range("A" & ChkRw + 1), 2) Then
Range("A" & ChkRw + 1).EntireRow.Insert Shift:=xlDown
Range("A" & ChkRw + 1).EntireRow.Insert Shift:=xlDown
Range("A" & ChkRw + 1).Value = "Date"
Range("B" & ChkRw + 1).Value = "Amount"
Range("C" & ChkRw + 1).Value = "Description"
Range("A" & ChkRw + 1).EntireRow.Insert Shift:=xlDown
Range("A" & ChkRw + 1).EntireRow.Insert Shift:=xlDown
Range("B" & ChkRw + 1).Value = Range("D1")
Range("A" & ChkRw + 1).EntireRow.Insert Shift:=xlDown
Range("A" & ChkRw + 1).EntireRow.Insert Shift:=xlDown
Range("A" & ChkRw + 1).Value = "Total"
Range("A" & ChkRw + 1).EntireRow.Insert Shift:=xlDown
End If
Next
'Cells.Find(what:="total").Activate
'ActiveCell.Offset(0, 1).Activate
'x = ActiveCell.Column: y = ActiveCell.Row
End Sub
Last edited: