+ Reply to Thread
Results 1 to 7 of 7

Sorting table using VBA

  1. #1
    Registered User
    Join Date
    07-25-2019
    Location
    Klaipeda, Lithuania
    MS-Off Ver
    Microsoft Office 2017
    Posts
    51

    Sorting table using VBA

    Hello,

    I've created a table and a macro command "Testas2", which sorts a table depending on few columns. But my macro command excludes the first row (except a header). What am I doing wrong?
    Attached Files Attached Files

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Sorting table using VBA

    I don't see a sorting macro in that workbook (although my Excel had to repair it to open it).
    Rory

  3. #3
    Registered User
    Join Date
    07-25-2019
    Location
    Klaipeda, Lithuania
    MS-Off Ver
    Microsoft Office 2017
    Posts
    51

    Re: Sorting table using VBA

    I have attached a new workbook. The table is in Sheet1. Macro name is "Testas2"
    Attached Files Attached Files

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Sorting table using VBA

    Why are you using Testas2 rather than Testas which uses the correct syntax for sorting a table.

  5. #5
    Registered User
    Join Date
    07-25-2019
    Location
    Klaipeda, Lithuania
    MS-Off Ver
    Microsoft Office 2017
    Posts
    51

    Re: Sorting table using VBA

    testas works just for sorting column B "Gofra". But I want to sort table by column B, then by column C then by E and finally by column F. Testas2 works with that, but excludes the first row

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Sorting table using VBA

    All you need to do is repeat the sortfields.add line with the additional columns, in order.

  7. #7
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: Sorting table using VBA

    You have declared table1 as A7:L14, Which excludes the header row. But in the code it is shown
    .Header = xlYes.
    So it excludes the the first row of Table1(Row7)

    Change the above line in the code as

    .Header = xlNo

    Or

    Declare the table range as A6:L14.
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 17
    Last Post: 07-05-2021, 07:20 AM
  2. Sorting Pivot Table Pulling from Power Query Data Table
    By perkyparker in forum Office 365
    Replies: 1
    Last Post: 05-22-2021, 03:02 PM
  3. Custom Sorting a Slicer for a table - not a pivot table
    By Melissalee71 in forum Excel General
    Replies: 1
    Last Post: 10-12-2018, 10:23 AM
  4. Replies: 0
    Last Post: 02-24-2014, 11:27 AM
  5. [SOLVED] Sorting a pivot table and data outside of the table
    By nicki_rae22 in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 12-06-2013, 12:57 PM
  6. Replies: 9
    Last Post: 02-01-2011, 08:47 AM
  7. Copying data from one table to another table and sorting it
    By bmohor3 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-01-2011, 02:50 AM

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