Patriot2879
Well-known Member
- Joined
- Feb 1, 2018
- Messages
- 1,259
- Office Version
- 2010
- Platform
- Windows
Hi just wondering is there any way of tidying up the code below as it is repeated quite a lot just wondering if there was a easier/better way in putting it all together. hope you can help.
Code:
Private Sub CommandButton3_Click()
With Sheets("Sheet1")
.Columns("C:C").Sort Key1:=.Range("C:C"), Order1:=xlDescending, Header:=xlYes
End With
Set copySheet = Worksheets("Sheet1")
Set pasteSheet = Worksheets("New")
With copySheet
.Range(.Cells(2, "C"), .Cells(.Cells(Rows.Count, "C").End(xlUp).Row, "C")).Copy
End With
pasteSheet.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Range("B2", Range("B2").End(xlDown)).NumberFormat = "0"
With copySheet
.Range(.Cells(2, "F"), .Cells(.Cells(Rows.Count, "F").End(xlUp).Row, "F")).Copy
End With
pasteSheet.Cells(Rows.Count, 33).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
With copySheet
.Range(.Cells(2, "F"), .Cells(.Cells(Rows.Count, "F").End(xlUp).Row, "F")).Copy
End With
pasteSheet.Cells(Rows.Count, 34).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
With copySheet
.Range(.Cells(2, "L"), .Cells(.Cells(Rows.Count, "L").End(xlUp).Row, "L")).Copy
End With
pasteSheet.Cells(Rows.Count, 8).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
With copySheet
.Range(.Cells(2, "M"), .Cells(.Cells(Rows.Count, "M").End(xlUp).Row, "M")).Copy
End With
pasteSheet.Cells(Rows.Count, 19).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
With copySheet
.Range(.Cells(2, "Q"), .Cells(.Cells(Rows.Count, "Q").End(xlUp).Row, "Q")).Copy
End With
pasteSheet.Cells(Rows.Count, 17).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Application.ScreenUpdating = False
With Range("Q2", Range("Q" & Rows.Count).End(xlUp))
.EntireColumn.Insert
.NumberFormat = "@"
With .Offset(, -1)
.FormulaR1C1 = "=Text(RC[1],""dd/mm/YYYY"")"
.Offset(, 1).Value = .Value
.EntireColumn.Delete
End With
End With
Application.ScreenUpdating = True
lr = Sheets("New").Cells(Rows.Count, "B").End(xlUp).Row
Sheets("New").Range("A3:A" & lr) = Sheets("New").Range("A2")
End Sub