Codes Need to be Concise

ayazgreat

Well-known Member
Joined
Jan 19, 2008
Messages
1,151
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.

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
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Datsmart

Well-known Member
Joined
Jun 19, 2003
Messages
7,985
ADVERTISEMENT
Since I do not have access to your data, it is very difficult to give you any advice on your code.

Does it do what you want it to?
Are you getting any errors?

I have viewed some of your other threads and they are equally vague without a specific question.
Please ask your question differently and you should get a better response.
 
Upvote 0

ayazgreat

Well-known Member
Joined
Jan 19, 2008
Messages
1,151
Thanks Sir for your reply I have written first time a long macro or u can say that it is my first attempt I want to ask that given codes are possible to be concise and check however these do not give any error.
 
Upvote 0

ayazgreat

Well-known Member
Joined
Jan 19, 2008
Messages
1,151
ADVERTISEMENT
Since I do not have access to your data, it is very difficult to give you any advice on your code.

Then who will answer it ?
 
Upvote 0

ayazgreat

Well-known Member
Joined
Jan 19, 2008
Messages
1,151
Thank you very much Sir and it is my good luck that i have got chance to talk to you because I have learnt lots from your site and have been still learing and trying to understand your gievn examples and studies cases but I must appreciate your efforts.
 
Upvote 0

Forum statistics

Threads
1,195,743
Messages
6,011,395
Members
441,612
Latest member
npasha1

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
Top