+ Reply to Thread
Results 1 to 3 of 3

XL03 Sort error: "Method 'Range' of object '_Worksheet' failed"

Hybrid View

  1. #1
    Registered User
    Join Date
    06-28-2011
    Location
    Bristol, UK
    MS-Off Ver
    Excel 2010, 2013, 2016, 365
    Posts
    79

    Exclamation XL03 Sort error: "Method 'Range' of object '_Worksheet' failed"

    Hi All,

    I have had to modify some code written in XL07 to be back-compatible with XL03 (thread here) but the resulting code (below) keeps falling over with a 1004 error (Method 'Range' of object '_Worksheet' failed) at the line underlined:

    Sub VT_Filter()
    Sheets("Dashboard").Calculate
    
    Dim ws As Worksheet
    Dim Str_Ce1, Str_Ce2, str_Key1, str_Key2 As String
    Dim Byt_j As Byte        
    Dim rge_Sort As Range
    
    Set ws = Sheets("CHART DATA")
    With ws
        .Range("$A$8:$T$305").AutoFilter
        
         For Byt_j = 1 To 4
                    
            Str_Ce1 = Choose(Byt_j, "9", "52", "123", "208")
            Str_Ce2 = Choose(Byt_j, "50", "121", "206", "305")
    
            Set rge_Sort = ws.Range("A" & Str_Ce1 & ":T" & Str_Ce2)
            str_Key1 = "B" & Str_Ce1 & ":B" & Str_Ce2
            str_Key2 = "E" & Str_Ce1 & ":E" & Str_Ce2
            
            Sheets("test").Range("A1").Value = str_Key1
            
            rge_Sort.Sort _
                    Key1:=ws.Range("str_Key1"), Order1:=xlAscending, _
                    Key2:=ws.Range("str_Key2"), Order2:=xlAscending, _
                    header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
                    Orientation:=xlTopToBottom, DataOption1:=xlSortNormal         
    
         Next Byt_j
        
         With .Range("$A$8:$T$305")
        
            .AutoFilter 2, "<>False"
            .AutoFilter 7, "<>False"
            
         End With
      End With
      
    End Sub
    Could anyone help with this?

    Many thanks,
    AdLoki
    Last edited by AdLoki; 07-07-2011 at 08:23 AM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,309

    Re: XL03 Sort error: "Method 'Range' of object '_Worksheet' failed"

    Change the sort keys to:
           str_Key1 = "B" & Str_Ce1
            str_Key2 = "E" & Str_Ce1
    and then use:
           rge_Sort.Sort _
                    Key1:=ws.Range(str_Key1), Order1:=xlAscending, _
                    Key2:=ws.Range(str_Key2), Order2:=xlAscending, _
                    header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
                    Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
    Anyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    06-28-2011
    Location
    Bristol, UK
    MS-Off Ver
    Excel 2010, 2013, 2016, 365
    Posts
    79

    Re: XL03 Sort error: "Method 'Range' of object '_Worksheet' failed"

    Thank you!! So obvious, I was staring at it for so long, couldn't see the wood for the trees!

    Life saver, thanks again romperstomper

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.6.0 RC 1