+ Reply to Thread
Results 1 to 9 of 9

Macro to sort and place data in adjacent columns

  1. #1
    Registered User
    Join Date
    07-10-2012
    Location
    NSW, Australia
    MS-Off Ver
    Excel 2010
    Posts
    76

    Macro to sort and place data in adjacent columns

    Hello

    I am trying to create a macro to sort some data and then place it in separate in tabs depending on the case. There are 3 possible cases in Col A (ABC), 2 cases in Col B (1,2) and col C and D contain values.
    I have attached an example excel file which illustrates the problem. Basically, the process is the same sorting all the data by col A, then col B, then col C, and then copying each group across into separate tabs.

    While sorting data using the "sort" function in the "data" tab and copying and pasting is a simple way to achieve the outcome it is a bit time consuming, and as I need to do this for >150 different files, if it were possible to create a macro to automate this process I would be very grateful.

    Please contact me if you require any further information.

    I thank you in advance for your assistance

    T15K
    Attached Files Attached Files

  2. #2
    Forum Contributor noboffinme's Avatar
    Join Date
    08-29-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003/7/10/13/16/19
    Posts
    1,071

    Re: Macro to sort and place data in adjacent columns

    Hi T15K,

    Can you be a bit more specific about what you want this macro to do?

    Could you describe it in steps such as

    1."Sort Column 'A' on the 'Raw Data' worksheet, then Copy Columns 'A' - 'D' & Paste the Range 'A2'-'D6' into the 'A1' worksheet in the correct Columns" for example.

    2.Next step

    3.Next step

    Thanks
    Remember you are unique, like everyone else

  3. #3
    Registered User
    Join Date
    07-10-2012
    Location
    NSW, Australia
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Macro to sort and place data in adjacent columns

    As you can see in the example spread sheet, I would like a macro that copies rows of data from the raw data tab into the corresponding tab based on the value that appears in Col A and Col B. For example, if there is A in col A, and B in col 1, then copy that row of data into the tab called A1. If the data is C in Col A and 2 in Col B, then that row of data is copied into the tab called C2.

    I hope this clears it up
    T15K

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro to sort and place data in adjacent columns

    Does this help?

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-10-2012
    Location
    NSW, Australia
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Macro to sort and place data in adjacent columns

    Hi John,

    Thank you for that excellent solution. Can I just request one modification?
    The macro that you created adds new tabs for each type of data (E.g A1, B2 etc).
    Would it be possible for me to already have the tabs set up and named in the worksheet, and then the macro just copies the data into the corresponding existing named tab?
    The reason for this request is that I need to have some other basic formulas and formatting already set up in each tab, and then just have the data fed into there, rather having the macro create a new tab each time. Does this make sense?

    I hope this is not too difficult to do and I thank you again for your help so far.

    T15K

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro to sort and place data in adjacent columns

    It doesn't sound too difficult. Can you provide the tab names? Also an attachment with a sample of where to paste?

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro to sort and place data in adjacent columns

    See if this helps?

    Please Login or Register  to view this content.
    It assumes the Sheet names are set up as before with the Category and Type.

  8. #8
    Registered User
    Join Date
    07-10-2012
    Location
    NSW, Australia
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Macro to sort and place data in adjacent columns

    Thanks John. That is perfect. Thank you very much for your help.

  9. #9
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro to sort and place data in adjacent columns

    You're welcome. Glad to help out and thanks for the feedback. Please comply with Forum Rule No. 9.


    9. Acknowledge the responses you receive, good or bad. If your problem is solved, please say so clearly, and mark your thread as Solved: Click Thread Tools above your first post, select "Mark your thread as Solved". Or click the Edit button on your first post in the thread, Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Dropdown option or Edit button will not appear -- ask a moderator to mark it.

+ 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] Macro to copy 3 adjacent columns at a time to a separate worksheet & sort by Company name
    By anya1 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-20-2013, 06:50 AM
  2. Auto sort code to include adjacent columns
    By Frantelle in forum Excel General
    Replies: 3
    Last Post: 11-17-2012, 11:47 AM
  3. Sort but keep linked data in place
    By MAMc in forum Excel General
    Replies: 2
    Last Post: 11-02-2011, 03:02 PM
  4. Macro to sort data by columns
    By Cornfused in forum Excel General
    Replies: 15
    Last Post: 12-10-2010, 12:51 PM
  5. [SOLVED] How do I create a macro that will compare columns and place data
    By CompuCat in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-20-2006, 02:25 PM

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