+ Reply to Thread
Results 1 to 8 of 8

Macro to sort Columns in correct oder

  1. #1
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2024
    Posts
    2,876

    Macro to sort Columns in correct oder

    I have data that I import and need the columns copied/sorted in a specific order

    The column headers will always start from Row5 and the data will be below this

    I have show in row 4 what sequence the headers must be in

    It would be appreciated if someone can provide me with code to ensure the columns are in the correct sequence
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Macro to sort Columns in correct oder


    In the destination sheet allocate the headers with the correct order but with the same exact spelling than your import sheet
    so no typo is allowed then just use an easy beginner level advanced filter to copy the data from the import sheet to the destination sheet,
    needing only a single codeline ! …

  3. #3
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2024
    Posts
    2,876

    Re: Macro to sort Columns in correct oder

    Thanks for your input. I have tried to set up advanced filtering but cannot get it to extract the columns in the correct order per the criteria on sheet2

    Once I have got it manually correct, then I will write a macro

    Please check & advise
    Attached Files Attached Files

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,378

    Re: Macro to sort Columns in correct oder

    Hi Howardc,

    A little known feature of Advanced Filter is that you can rearrange the order of the columns or limit the columns if you select a "Copy To:" range that already has those column heads in it. See the attached where the sample data is on the left and I filled in the Copy To range using the column heads only in Row 5, but in different order. Then do the Advanced filter using the range that is the columns you want to see and in which order. This could be the answer to easily rearranging your columns. Hope this helps.
    Macro to Sort columns in Correct Order Using Adv Filter.xlsm
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Macro to sort Columns in correct oder


    Howard,

    using an advanced filter is at kid level as it must work without any headers error so I wanna see your try …

    If operating manually the well known tip is to start from the destination sheet (so must be the active sheet).
    Last edited by Marc L; 04-06-2020 at 12:02 PM.

  6. #6
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2024
    Posts
    2,876

    Re: Macro to sort Columns in correct oder

    Hi Marvin

    Thanks for the explanation.

    I did the following steps using advanced filter without using the criteria section

    1) I selected range A5:U6 (list range)
    2) I then selected copy to and selected AB5:UV5

    When click ok I get an error message

    I am obviously missing something

    Please explain step by step what I need to do

    Many Thanks

    Howard
    Attached Files Attached Files

  7. #7
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,378

    Re: Macro to sort Columns in correct oder

    Hey Howard,

    I think Mark got the answer for your error before you asked. You need to start the Advanced Filter dialog on the sheet where the Criteria is located. If you told us the error message we could have been more sure that was the problem. Read a list of possible problems at:
    https://answers.microsoft.com/en-us/...2-c8c86600a9e2

  8. #8
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2024
    Posts
    2,876

    Re: Macro to sort Columns in correct oder

    Hi Marvin & Mark

    Many thanks for all your valuable input.

    My apologies. One of the headers in the copy to section was incorrect resulting in the error. I have used advanced filtering fairly often and have never encountered a problem as it is simple to use

    I have never used the copy to without criteria
    Last edited by Howardc1001; 04-06-2020 at 01:22 PM.

+ 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. [SOLVED] Table oder by arrays
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-07-2015, 06:49 PM
  2. Lösung über Formel oder VBA
    By eugen.hasilbach in forum Excel General
    Replies: 9
    Last Post: 02-17-2015, 09:18 AM
  3. [SOLVED] Excel VBA Kopierern durch .Workbooks. .. oder .Windows. .. OOP
    By Doc.AElstein in forum Non English Excel
    Replies: 1
    Last Post: 10-03-2014, 06:26 AM
  4. [SOLVED] Range Address Is Correct Columns Count Is Not Correct
    By goss in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-09-2013, 12:47 PM
  5. Macro to filter and sort by multiple categories & Send to correct sheet
    By lax2734 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-08-2013, 08:35 PM
  6. Replies: 0
    Last Post: 01-29-2013, 06:01 AM
  7. Sort names (first,last) into correct columns
    By treva26 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-21-2007, 03:22 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