Livin404
Well-known Member
- Joined
- Jan 7, 2019
- Messages
- 743
- Office Version
- 365
- 2019
- Platform
- Windows
Greetings, I have a VBA which works great in sorting out a column from oldest to newest while expanding the columns and finally refreshing (Using Pivot Tables). I would like the VBA to be change from "With ActiveSheet" to state a another worksheet "Air Outbound". I need my Command Button on a different workseet. Thank you so much,
VBA Code:
Private Sub CommandButton2_Click()
Dim xlSort As XlSortOrder
Dim LastRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
If (.Range("A2").Value > .Range("A" & CStr(LastRow))) Then
xlSort = xlAscending
End If
Range("A1") = "Date"
.Columns("A:N").Sort key1:=Range("A2"), order1:=xlAscending, Header:=xlYes
End With
ActiveWorkbook.RefreshAll
End Sub