ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,226
- Office Version
- 2007
- Platform
- Windows
Morning,
I am using the code supplied below.
Currently i make a selection from the drop down list & press CommandButton1 to run the code.
The selected column is then sorted perfect A-Z & then as shown in red below cell A4 is selected.
Im looking to have the ability to not select A4 all the time BUT to select the cell in row 4 for which column i asked to be sorted.
So if i select YEAR from the drop down list i expect after the sort cell D to be selected.
Im not sure on how to do thi but i assuming an IF statement would be the answer,Something like,
As you can see im poor at this but can follow advice once given.
Thanks
I am using the code supplied below.
Currently i make a selection from the drop down list & press CommandButton1 to run the code.
The selected column is then sorted perfect A-Z & then as shown in red below cell A4 is selected.
Im looking to have the ability to not select A4 all the time BUT to select the cell in row 4 for which column i asked to be sorted.
So if i select YEAR from the drop down list i expect after the sort cell D to be selected.
Im not sure on how to do thi but i assuming an IF statement would be the answer,Something like,
Rich (BB code):
If
ComboBox1 selection = A Then
Cell A4.select
Else If
ComboBox1 selection = B Then
Cell B4.Select
As you can see im poor at this but can follow advice once given.
Thanks
Rich (BB code):
Private Sub CommandButton1_Click()
Dim x As Long
Dim WS As Worksheet
Set WS = Sheets("HONDA LIST")
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
Range("A4").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("A3:G" & x).Sort Key1:=.Cells(2, SortColumn), Order1:=xlAscending, Header:=xlGuess
End With
End If
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim rheadings As Range
Dim cl As Range
Set rheadings = Worksheets("HONDA LIST").Range("A2:G2")
For Each cl In rheadings
Me.ComboBox1.AddItem cl.Value
Next cl
End Sub