split data to multiple sheets based on month and summing the values

MKLAQ

Active Member
Joined
Jan 30, 2021
Messages
398
Office Version
  1. 2016
Platform
  1. Windows
hello
I have data in sheet ENTER what I want creating multiple sheets for JAN up o DEC it should copy data from sheet ENTER to sheet relating the month based on COL A in sheet ENTER for instance any data are in JAN month then should copy to sheet JAN and so on the rest of sheets and if I change the data in sheet ENTER then should update the relating sheet months and show the total
sheet ENTER
REPORT (2).xlsx
ABCDE
1DATEBRANDTYPEMODELQTY
21/1/2021CC-SSBMW2010250
31/2/2021CC-SSBMW2011125
41/3/2021CC-SSBMW201366
51/4/2021CC-MMMER202055
62/5/2021CC-MMMER202188
72/6/2021CC-MMMER201799
82/7/2021CC-LLAUDI201114
92/8/2021CC-LLAUDI201512
103/9/2021CC-LLAUDI201615
ENTER


desire result
sheet JAN
REPORT (2).xlsx
ABCDE
1DATEBRANDTYPEMODELQTY
21/1/2021CC-SSBMW2010250
31/2/2021CC-SSBMW2011125
41/3/2021CC-SSBMW201366
51/4/2021CC-MMMER202055
6LTT496
JAN


sheet FEB
REPORT (2).xlsx
BCDEF
22/5/2021CC-MMMER202188
32/6/2021CC-MMMER201799
42/7/2021CC-LLAUDI201114
52/8/2021CC-LLAUDI201512
6LTT213
FEB

sheet MAR
REPORT (2).xlsx
ABCDE
1DATEBRANDTYPEMODELQTY
23/9/2021CC-LLAUDI201615
3LTT15
MAR
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
This macro should create the monthly sheets.
VBA Code:
Sub CreateSheets()
    Application.ScreenUpdating = False
    Dim LastRow As Long, srcWS As Worksheet, ldatefrom As Long, ldateto As Long, lMon As Long, x As Long, yr As Long, mName As String
    Set srcWS = Sheets("ENTER")
    LastRow = srcWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    lMon = Month(WorksheetFunction.Max(srcWS.Range("A:A")))
    yr = Year(Range("A2"))
    For x = 1 To lMon
        mName = Left(MonthName(x), 3)
        ldatefrom = DateSerial(yr, x, 1)
        ldateto = DateSerial(yr, x + 1, 0)
        With srcWS.Range("A1").CurrentRegion
            .AutoFilter Field:=1, Criteria1:=">=" & ldatefrom, Operator:=xlAnd, Criteria2:="<=" & ldateto
            If Not Evaluate("isref('" & mName & "'!A1)") Then
               Sheets.Add(After:=Sheets(Sheets.Count)).Name = mName
               srcWS.AutoFilter.Range.Copy Range("A1")
               Cells(Rows.Count, "A").End(xlUp).Offset(1) = "LTT"
               Cells(Rows.Count, "E").End(xlUp).Offset(1).Formula = WorksheetFunction.Sum(Range("E2", Range("E" & Rows.Count).End(xlUp)))
            End If
        End With
    Next x
    srcWS.Range("A1").AutoFilter
    Application.ScreenUpdating = True
End Sub
If you want to update the monthly sheets each time you change the data in sheet ENTER, then each row in sheet ENTER will need a unique identifier. The date in column A could be used as the unique identifier as long as there are no duplicate dates in column A. Can column A contain duplicate dates? If it can, then you will need to add another column with a unique identifier for each row. It can be as simple as consecutive numbers as shown below or you can use any value you want as long as there are no duplicates in column A. Would this work for you?
Book1
ABCDEF
1IDDATEBRANDTYPEMODELQTY
211/1/2021CC-SSBMW2010250
321/2/2021CC-SSBMW2011125
431/3/2021CC-SSBMW201366
541/4/2021CC-MMMER202055
652/5/2021CC-MMMER202188
762/6/2021CC-MMMER201799
872/7/2021CC-LLAUDI201114
982/8/2021CC-LLAUDI201512
1093/9/2021CC-LLAUDI201615
ENTER
 
Upvote 0
thanks
Can column A contain duplicate dates?
yes , and I want the ID merges the values in COL C,D,E like this CC-SS -BMW- 2010
note: should highlight the LTT row as I did it
 
Upvote 0
Can the date also change? If you change the month in any date, that creates a problem because the data on the row with the changed month will be on a different monthly sheet. How do you want to handle this possibility?
 
Upvote 0
I suppose if the change in day this is not problem , it keeps in the same month but if I change the month you right, it occurs a problem , in this case should delete from the previous month and updating in a new month
 
Upvote 0
Upvote 0
Click here for your file. Give it a try and see how it works out. These macros are in the "ENTER" sheet code module.
VBA Code:
Dim oldDate As String
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Select Case Target.Column
        Case Is = 2
            Range("AA1") = Target
        Case Is = 3, 4, 5, 6
            Range("AA1") = Range("A" & Target.Row)
    End Select
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Target.Column = 1 Then Exit Sub
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Dim ws As Worksheet, ID As Range
    Select Case Target.Column
        Case Is = 2
            If Month(Range("AA1")) = Month(Target) Then
                Set ws = Sheets(Left(MonthName(Month(Target)), 3))
                Set ID = ws.Range("A:A").Find(Target.Offset(, -1), LookIn:=xlValues, lookat:=xlWhole)
                If Not ID Is Nothing Then
                    Target.Offset(, -1).Resize(, 6).Copy ws.Range("A" & ID.Row)
                End If
            Else
                If Evaluate("isref('" & Left(MonthName(Month(Target)), 3) & "'!A1)") Then
                    Set ws = Sheets(Left(MonthName(Month(Target)), 3))
                    With ws
                        Target.Offset(, -1).Resize(, 6).Copy .Cells(.Rows.Count, "A").End(xlUp)
                        .Cells(.Rows.Count, "A").End(xlUp).Offset(1) = "LTT"
                        .Cells(.Rows.Count, "E").End(xlUp).Offset(1).Formula = WorksheetFunction.Sum(.Range("E2", .Range("E" & .Rows.Count).End(xlUp)))
                        .Cells.WrapText = False
                        .Columns.AutoFit
                    End With
                    Set ID = Sheets(Left(MonthName(Month(Range("AA1"))), 3)).Range("A:A").Find(Target.Offset(, -1), LookIn:=xlValues, lookat:=xlWhole)
                    ID.EntireRow.Delete
                Else
                    Sheets.Add(After:=Sheets(Sheets.Count)).Name = Left(MonthName(Month(Target)), 3)
                    With ActiveSheet
                        Sheets("ENTER").Range("A1:F1").Copy .Range("A1")
                        Target.Offset(, -1).Resize(, 6).Copy .Cells(.Rows.Count, "A").End(xlUp).Offset(1)
                        .Cells(.Rows.Count, "A").End(xlUp).Offset(1) = "LTT"
                        .Cells(.Rows.Count, "E").End(xlUp).Offset(1).Formula = WorksheetFunction.Sum(.Range("E2", .Range("E" & .Rows.Count).End(xlUp)))
                        .Columns.AutoFit
                    End With
                    Set ID = Sheets(Left(MonthName(Month(Range("AA1"))), 3)).Range("A:A").Find(Target.Offset(, -1), LookIn:=xlValues, lookat:=xlWhole)
                    ID.EntireRow.Delete
                End If
            End If
        Case Is = 3, 4, 5, 6
            Set ws = Sheets(Left(MonthName(Month(Range("B" & Target.Row))), 3))
            Set ID = ws.Range("A:A").Find(Range("AA1"), LookIn:=xlValues, lookat:=xlWhole)
            ws.Cells(ID.Row, Target.Column) = Target
    End Select
    Range("AA1").ClearContents
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,113
Messages
6,128,904
Members
449,477
Latest member
panjongshing

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