my code is as follows:
Private Sub CommandButton2_Click()
Sheets("Head").Select
ActiveSheet.Range("B3:B14").Select
Selection.Copy
Sheets("Ref").Select
ActiveSheet.Range("A1").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
Selection.PasteSpecial Paste:=xlPasteValues, Transpose:=True
Sheets("Ref").Select '(there are many rows existing in "Ref")
Cells.Select
Application.CutCopyMode = False
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom,_ SortMethod:=xlPinYin, DataOption1:=xlSortNormal
End Sub
Error code 1004 - I dont understand what is the problem. Without coding, the data sorting works fine, but not in code.
Any suggestions
TIA
norika
Try to change your sort code so:
Usually in sort instruction is useful to put refer to sheet each time you use Range instruction.With Sheets("Ref").Cells .Sort Key1:=.Range("A2"), Order1:=xlAscending, Header:=xlYes, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ SortMethod:=xlPinYin, DataOption1:=xlSortNormal End With
I hope it helps.
Regards,
Antonio
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks