I have a macro attached to a button (each sheet actually has 4 macros attached to four buttons... but they are all virtually identical).
Macro to sort range A5:E5 downwards (sorting by column A) works perfectly, until data is added to column D. When any data is added to column D the top row of the range will not sort. Values in column D are formatted as number, to one decimal place.
Would anyone be able to look at the following code and tell me where I'm going wrong?
Just for info, rows 1 to 4 are just 'title' rows and are merged (or not) according to a preferred visual style.
Bit of a macro/code newbie... go easy on me!
Thanks!
Private Sub CommandButton1_Click()
Static iOrder As Integer
Dim oRange As Range
If iOrder = xlAscending Then
iOrder = xlDescending
Else
iOrder = xlAscending
End If
Set oRange = Range("A5:E5")
Set oRange = Range(oRange, oRange.End(xlDown))
oRange.Sort Key1:=Range("A5"), Order1:=iOrder, Header:=x0Guess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub
Macro to sort range A5:E5 downwards (sorting by column A) works perfectly, until data is added to column D. When any data is added to column D the top row of the range will not sort. Values in column D are formatted as number, to one decimal place.
Would anyone be able to look at the following code and tell me where I'm going wrong?
Just for info, rows 1 to 4 are just 'title' rows and are merged (or not) according to a preferred visual style.
Bit of a macro/code newbie... go easy on me!
Thanks!
Private Sub CommandButton1_Click()
Static iOrder As Integer
Dim oRange As Range
If iOrder = xlAscending Then
iOrder = xlDescending
Else
iOrder = xlAscending
End If
Set oRange = Range("A5:E5")
Set oRange = Range(oRange, oRange.End(xlDown))
oRange.Sort Key1:=Range("A5"), Order1:=iOrder, Header:=x0Guess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub