Sir Vog-II/Jindon
I have written mentioned below codes to copy data with certain craiteria can you please see them if these codes need to be improved or concise.
I have written mentioned below codes to copy data with certain craiteria can you please see them if these codes need to be improved or concise.
HTML:
Sub ayazgreat()
Dim Header
Dim Header2
Dim LastRow As Long
Dim Rng As Range
Header = Array("Region", "Item Issued", "Invoice Date", "Cheque #", "Amount", "Chq Date")
Header2 = "Total"
With Application
.ScreenUpdating = False
.DisplayAlerts = False
Sheets("Payment").Copy
ActiveSheet.Shapes("Button 1").Delete
ActiveSheet.Shapes("Button 2").Delete
Rows("1:2").Delete Shift:=xlUp
ActiveSheet.Range("C3:H3").Value = Header
ActiveSheet.Columns("E:H").AutoFit
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Set Rng = Range("A3:H" & Range("A" & Rows.Count).End(xlUp).Row)
Range("A" & LastRow, "H" & LastRow).Delete
Rng.Sort Key1:=Range("C4"), Order1:=xlAscending
Rng.AutoFilter Field:=3, Criteria1:="S-II"
Rng.SpecialCells(xlCellTypeVisible).Copy _
Destination:=Sheets("Payment").Range("J3")
Rng.AutoFilter
LastRow = Range("J" & Rows.Count).End(xlUp).Row
Range("J" & LastRow + 1, "O" & LastRow + 1).Merge
Range("J" & LastRow + 1) = Header2
Range("J" & LastRow + 1, "Q" & LastRow + 1).Interior.Color = 0
Range("J" & LastRow + 1, "Q" & LastRow + 1).Font.Bold = True
Range("J" & LastRow + 1, "Q" & LastRow + 1).Font.ColorIndex = 2
Range("J" & LastRow + 1, "O" & LastRow + 1).HorizontalAlignment = xlCenter
Range("P" & LastRow + 1).Value = WorksheetFunction.Sum(Range("P4:P" & LastRow))
Rng.AutoFilter Field:=3, Criteria1:="S-III"
Rng.SpecialCells(xlCellTypeVisible).Copy _
Destination:=Sheets("Payment").Range("S3")
Rng.AutoFilter
LastRow = Range("S" & Rows.Count).End(xlUp).Row
Range("S" & LastRow + 1, "X" & LastRow + 1).Merge
Range("S" & LastRow + 1) = Header2
Range("S" & LastRow + 1, "Z" & LastRow + 1).Interior.Color = 0
Range("S" & LastRow + 1, "Z" & LastRow + 1).Font.Bold = True
Range("S" & LastRow + 1, "Z" & LastRow + 1).Font.ColorIndex = 2
Range("S" & LastRow + 1, "X" & LastRow + 1).HorizontalAlignment = xlCenter
Range("Y" & LastRow + 1).Value = WorksheetFunction.Sum(Range("Y4:Y" & LastRow))
Range("S3:Z2000").Copy
Cells(Rows.Count, "J").End(xlUp).Offset(3).PasteSpecial xlAll
Columns("S:Z").Delete
Columns("A:I").Delete
Range("A4").Select
.ScreenUpdating = True
.DisplayAlerts = True
End With
End Sub