What I want to do is use a select case statement within a statement, for example.
I want to make this code
Work Like the code below, having a embedded select case statement within a statement so to cut down on the amount of code that I need to write.![]()
Sub Sort_by(First_Sort As String, Optional Second_Sort As String) If Second_Sort = "" Then Select Case First_Sort Case A Cells.Select 'Sort by Sku Selection.Sort Key1:=Range("A" & "2"), Order1:=xlAscending, Header:=xlYes, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortTextAsNumbers Case B Cells.Select 'Sort by Core/Partner Selection.Sort Key1:=Range("B"& "2"), Order1:=xlAscending, Header:=xlYes, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortTextAsNumbers End Select End If End Sub
Or does anyone know of a simple way to do this?
Does that make sense?![]()
Sub Sort_by(First_Sort As String, Optional Second_Sort As String) If Second_Sort = "" Then Select Case First_Sort Case "A" Cells.Select Selection.Sort Key1:=Range("A" & "2"), Order1:=xlAscending, _ Select Case Second_String Case A Key2:=Range("A2") _, Order2:=xlAscending, _ Case B Key2:=Range("B2") _, Order2:=xlAscending, _ End Select Header:=xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortTextAsNumbers Case "B"" Cells.Select 'Sort by Core/Partner Selection.Sort Key1:=Range("B" & "2"), Order1:=xlAscending, Header:=xlYes, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortTextAsNumbers End Select End If End Sub











LinkBack URL
About LinkBacks
Register To Reply
Bookmarks