Results 1 to 4 of 4

Compile Error while sorting with VBA

Threaded View

  1. #1
    Registered User
    Join Date
    06-04-2007
    MS-Off Ver
    Excel 2007
    Posts
    94

    Compile Error while sorting with VBA

    I am trying to sort data in a worksheet based on two criteria in two columns that are not adjacent, but I keep getting the error "Expected End With" but End With is in the macro

    Option Explicit
    
    Sub tester()
      Dim wks         As Worksheet
      Dim iRow        As Long
    
        For Each wks In ActiveWorkbook.Worksheets
            With wks
                With .Sort
                    .SortFields.Clear
                    .SortFields.Add Key:=Range("R:R"), _
                                    SortOn:=xlSortOnValues, _
                                    Order:=xlAscending, _
                                    DataOption:=xlSortNormal
                    .SortFields.Add Key:=Range("A:A"), _
                                    SortOn:=xlSortOnValues, _
                                    Order:=xlAscending, _
                                    DataOption:=xlSortNormal
                    .SetRange wks.Range("A:V")
                    .Header = xlYes
                    .MatchCase = False
                    .Orientation = xlTopToBottom
                    .Apply
         End With
     End Sub
    Attached is a sample worksheet
    Attached Files Attached Files
    Last edited by capnhud; 08-15-2011 at 01:21 PM.

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