Hi everyone,
I have the following problem that I hope somebody can help me with.
I have a table, that I want to sort in terms of row values (keeping the existing columns still corresponding with the new row order)
such that for example:
X Y Z
Age 74 53 62
Size 11 5 13
Becomes the following after sorting by age, for example: where Age is defined in a cell which I can then use as a dropdown menu:
Y Z X
Age 53 62 74
Size 5 13 11
I've tried using the following code:, where A1 in the case above, would be Age and the Range defines the table (including the row headings and column headings), but I just get a runtime error 1004. If I do the equivalent thing for sorting column values (change the data range to fit just the column and change to xlSortColumns/xlToptoBottom) it works for columns, but I can't get it to work for rows.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
myKey = Range("A1")
Range("G1:I4").Sort Key1:=myKey, Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlSortRows, _
DataOption1:=xlSortNormal
End If
End Sub
Thanks a lot for the help.
I have the following problem that I hope somebody can help me with.
I have a table, that I want to sort in terms of row values (keeping the existing columns still corresponding with the new row order)
such that for example:
X Y Z
Age 74 53 62
Size 11 5 13
Becomes the following after sorting by age, for example: where Age is defined in a cell which I can then use as a dropdown menu:
Y Z X
Age 53 62 74
Size 5 13 11
I've tried using the following code:, where A1 in the case above, would be Age and the Range defines the table (including the row headings and column headings), but I just get a runtime error 1004. If I do the equivalent thing for sorting column values (change the data range to fit just the column and change to xlSortColumns/xlToptoBottom) it works for columns, but I can't get it to work for rows.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
myKey = Range("A1")
Range("G1:I4").Sort Key1:=myKey, Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlSortRows, _
DataOption1:=xlSortNormal
End If
End Sub
Thanks a lot for the help.