Hi all,
I'm trying to write a simple prgramme that will be able to sort the table according the column number that is entered into an input box. i'm trying this but it crashes every time:
Sub Macro1()
Dim n As Integer
Dim mycell As Range
n = InputBox("Please enter which column you would like to sort by")
Set mycell = ActiveCell.Offset(0, n)
With mycell
Selection.CurrentRegion.Select
Selection.Sort Key1:=Range("mycell"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
End Sub
any ideas?
I'm trying to write a simple prgramme that will be able to sort the table according the column number that is entered into an input box. i'm trying this but it crashes every time:
Sub Macro1()
Dim n As Integer
Dim mycell As Range
n = InputBox("Please enter which column you would like to sort by")
Set mycell = ActiveCell.Offset(0, n)
With mycell
Selection.CurrentRegion.Select
Selection.Sort Key1:=Range("mycell"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
End Sub
any ideas?