ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,226
- Office Version
- 2007
- Platform
- Windows
Hi,
I am using the code supplied below.
All works fine BUT the sorting of the date sorts in the order of old to new from top to bottom of page.
I would also like the option to sort the date from new to old from top of page to bottom.
Originaly i was using the 2 codes also supplied but as you can see in this new code its compressed somewhat.
NEW TO OLD
OLD TO NEW
I am using the code supplied below.
All works fine BUT the sorting of the date sorts in the order of old to new from top to bottom of page.
I would also like the option to sort the date from new to old from top of page to bottom.
Originaly i was using the 2 codes also supplied but as you can see in this new code its compressed somewhat.
VBA Code:
Private Sub CommandButton1_Click()
Dim x As Long
Dim ws As Worksheet
Set ws = Sheets("HONDA SHEET")
Dim SortColumn As String
Select Case ComboBox1
Case "VIN NUMBER"
SortColumn = "A"
Case "VEHICLE"
SortColumn = "B"
Case "CUSTOMER"
SortColumn = "C"
Case "YEAR"
SortColumn = "D"
Case "HONDA NUMBER"
SortColumn = "E"
Case "SUPPLIED"
SortColumn = "F"
Case "DATE"
SortColumn = "G"
End Select
If Len(SortColumn) <> 0 Then
Application.ScreenUpdating = False
With ws
If .AutoFilterMode Then .AutoFilterMode = False
x = .Cells(.Rows.Count, 1).End(xlUp).Row
.Range("A20:G" & x).Sort Key1:=.Cells(2, SortColumn), Order1:=xlAscending, Header:=xlGuess
End With
End If
Unload AtoZHondaSheet
End Sub
Private Sub UserForm_Initialize()
Dim rheadings As Range
Dim cl As Range
Set rheadings = Worksheets("HONDA SHEET").Range("A19:G19")
For Each cl In rheadings
Me.ComboBox1.AddItem cl.Value
Next cl
End Sub
NEW TO OLD
Code:
Private Sub SortDatenewold_Click()
Dim x As Long
Application.ScreenUpdating = False
With Sheets("HONDA LIST")
If .AutoFilterMode Then .AutoFilterMode = False
x = .Cells(.Rows.Count, 1).End(xlUp).Row
.Range("A3:G" & x).Sort Key1:=Range("G4"), Order1:=xlDescending, Header:=xlGuess
End With
ActiveWorkbook.Save
Application.ScreenUpdating = True
Sheets("HONDA LIST").Range("G4").Select
End Sub
OLD TO NEW
Code:
Private Sub SortDateoldnew_Click()
Dim x As Long
Application.ScreenUpdating = False
With Sheets("HONDA LIST")
If .AutoFilterMode Then .AutoFilterMode = False
x = .Cells(.Rows.Count, 1).End(xlUp).Row
.Range("A3:G" & x).Sort Key1:=Range("G4"), Order1:=xlAscending, Header:=xlGuess
End With
ActiveWorkbook.Save
Application.ScreenUpdating = True
Sheets("HONDA LIST").Range("G4").Select
End Sub