+ Reply to Thread
Results 1 to 2 of 2

Thread: Data sort

  1. #1
    Registered User
    Join Date
    01-14-2004
    Posts
    22

    Data sort

    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

  2. #2
    Forum Guru
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2003
    Posts
    1,241
    Try to change your sort code so:
       With Sheets("Ref").Cells
          .Sort Key1:=.Range("A2"), Order1:=xlAscending, Header:=xlYes, _
             OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
             SortMethod:=xlPinYin, DataOption1:=xlSortNormal
       End With
    Usually in sort instruction is useful to put refer to sheet each time you use Range instruction.

    I hope it helps.

    Regards,
    Antonio

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0