Results 1 to 3 of 3

Automatically Sort Tables with Headers

Threaded View

dmacch24 Automatically Sort Tables... 04-10-2020, 08:55 AM
AliGW Re: Automatically Sort Tables... 04-10-2020, 09:35 AM
dmacch24 Re: Automatically Sort Tables... 04-10-2020, 09:39 AM
  1. #1
    Registered User
    Join Date
    04-10-2020
    Location
    New York
    MS-Off Ver
    2016
    Posts
    2

    Unhappy Automatically Sort Tables with Headers

    Hi


    I'm trying to automatically sort the 2 tables on a spreadsheet using the macro below, however when the macro runs, it sorts the headers to the bottom even though I wrote xlYes for header. I think this may have something to do with the fact that there is data above the headers because it works when there is nothing on top of the headers.

    The tables are located from C2:D5 and C12:D15 with numbers in cells C1,D1,C11, and D11 above the headers counting the number of cells.

    Any suggestions on how to fix? Thanks! I've attached a screenshot of the worksheet as well.
    Private Sub Worksheet_Change(ByVal Target As Range)
        On Error Resume Next
        If Not Intersect(Target, Range("A1:D5")) Is Nothing Then
            Range("c2").Sort Key1:=Range("c3"), _
              Order1:=xlAscending, Header:=xlYes, _
              OrderCustom:=1, MatchCase:=False, _
              Orientation:=xlTopToBottom
        End If
        If Not Intersect(Target, Range("A1:D14")) Is Nothing Then
            Range("c12").Sort Key1:=Range("c13"), _
              Order1:=xlAscending, Header:=xlYes, _
              OrderCustom:=1, MatchCase:=False, _
              Orientation:=xlTopToBottom
              End If
    End Sub
    Attached Images Attached Images
    Last edited by AliGW; 04-10-2020 at 09:36 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. autofilter method of range class failed -header has tables headers and non table headers
    By naveen.acheanz in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-16-2016, 08:21 AM
  2. [SOLVED] how to sort a sort data based on headers
    By luis6777 in forum Excel Formulas & Functions
    Replies: 23
    Last Post: 08-27-2015, 02:24 PM
  3. Update automatically tables with related headers that are in different sheets
    By cgkmal in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-09-2013, 08:39 PM
  4. Replies: 3
    Last Post: 09-30-2010, 12:30 PM
  5. Replies: 3
    Last Post: 05-08-2010, 08:47 AM
  6. Replies: 1
    Last Post: 03-09-2006, 01:24 PM
  7. [SOLVED] Automatically Sort Tables
    By tamato43 in forum Excel General
    Replies: 2
    Last Post: 03-22-2005, 04:06 PM

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