Hi could someone know how to code this macro? Is it correct? or does it has easier way to code this? like SUMIFS?
If there are 30 products, so there are 30 worksheet, and this product code will further split into 3 different categories. So I will have to create additional 3 tabs for each categories and need to sum up the values inside this 30 worksheets for respective categories.
Product start with C and end with 6 is called Lion
Product start with C and end with 3 is called Tiger
Product start with U and end with 4 is called Bird
Thank you !
If there are 30 products, so there are 30 worksheet, and this product code will further split into 3 different categories. So I will have to create additional 3 tabs for each categories and need to sum up the values inside this 30 worksheets for respective categories.
Product start with C and end with 6 is called Lion
Product start with C and end with 3 is called Tiger
Product start with U and end with 4 is called Bird
VBA Code:
Sub Macro45()
'
' Macro45 Macro"CrossMult_Validation")
'
Dim ws As Worksheet
Dim lLastRow As Long, i As Long
Dim RunningSum As Range
For Each ws In ThisWorkbook.Worksheets
If Left(ws.Name, 1) = "C" And Right(ws.Name, 1) = "6" Then
With ws
lLastRow = .Range("A" & .Rows.Count).End(xlUp).Row
.Parent.Sheets.Add After:=.Parent.Sheets(.Parent.Sheets.Count)
For i = 1 To lastRowData
.Cells(14, i + 1) = Application.WorksheetFunction.Sum(RunningSum)
Next i
.Name = "Lion"
End With
For Each ws In ThisWorkbook.Worksheets
If Left(ws.Name, 1) = "C" And Right(ws.Name, 1) = "3" Then
With ws
lLastRow = .Range("A" & .Rows.Count).End(xlUp).Row
.Parent.Sheets.Add After:=.Parent.Sheets(.Parent.Sheets.Count)
For i = 1 To lastRowData
.Cells(14, i + 1) = Application.WorksheetFunction.Sum(RunningSum)
Next i
.Name = "Tiger"
End With
For Each ws In ThisWorkbook.Worksheets
If Left(ws.Name, 1) = "U" And Right(ws.Name, 1) = "4" Then
With ws
lLastRow = .Range("A" & .Rows.Count).End(xlUp).Row
.Parent.Sheets.Add After:=.Parent.Sheets(.Parent.Sheets.Count)
For i = 1 To lastRowData
.Cells(14, i + 1) = Application.WorksheetFunction.Sum(RunningSum)
Next i
.Name = "Bird"
End With
End If
Next ws
End Sub
Thank you !