+ Reply to Thread
Results 1 to 6 of 6

Using VBA / Macro to autosort pairs of connecting columns and rows?

Hybrid View

  1. #1
    Registered User
    Join Date
    02-15-2013
    Location
    Edinburgh
    MS-Off Ver
    Excel 2007
    Posts
    3

    Post Using VBA / Macro to autosort pairs of connecting columns and rows?

    I have a series of columns that I want to autosort, selecting from a range of filters. Each pair of columns are connected, so I want to sort columns A and B; then columns C and D. I want the information in columns/rows to sort individually. Columns A is coded Red, Amber and Green, Column B included the connecting information. Columns C again is coded Red, Amber and Green with the connecting information. When I use the sort function it sorts each row of infromation from Column A across.
    Last edited by JBeaucaire; 02-16-2013 at 10:02 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Using VBA / Macro to autosort pairs of connecting columns and rows?

    You can highlight any two columns and sort just those two columns.

    Sorting by Cell Color is an option in the Sort Wizard in Excel 2010, is that available in Excel 2007?

    You can turn on the macro recorder and record it sorting your columns A:B the way you want. Then turn off the macro recorder.

    The resulting code could be used to create a looping macro that goes through all the columns on the Activesheet.

    Post a workbook if you want more specific help. Click GO ADVANCED and use the paperclip icon to post up a copy of your workbook. Use BEFORE/AFTER sheets in that workbook if that helps make it clearer.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    02-15-2013
    Location
    Edinburgh
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Using VBA / Macro to autosort pairs of connecting columns and rows?

    Thanks for your assistance.

    I have tried using autosort and sorting by pairs, but it filters across into the other columns and affects the rows. The filter does not restrict itself to the 2 columns selected.

    I have attached an rough example of the workbook I have in mind. I hope to use the paired columns filtering using R (red)A (amber) and G (green) building in suitable macros. The Auto filter selection would be ideal, as it only displays the requitred information but it runs across each row.

    TEST DATA - 16 FEBRUARY 2013.xlsx

    Many thanks

    Stephen

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Using VBA / Macro to autosort pairs of connecting columns and rows?

    The autosorting seems to work fine on the selected columns for autosorting: http://screencast.com/t/fS4TSngTu

  5. #5
    Registered User
    Join Date
    02-15-2013
    Location
    Edinburgh
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Using VBA / Macro to autosort pairs of connecting columns and rows?

    Quote Originally Posted by JBeaucaire View Post
    The autosorting seems to work fine on the selected columns for autosorting: http://screencast.com/t/fS4TSngTu
    Thanks again, re auto sort apologies for being a bit of a novice at this.

    The sort works fine, however what I was hoping to achieve is a selection of data in each column after selecting a specific criteria. For example selecting column A - RED returning only those corresponding entries associated in column B; and selecting RED in column C returning relevant entries in D.

    The filter function allows this in part, where I can select RED column A and it filters relevant/corresponding entries in column B. I cannot restrict the filter to only two columns in filters across each row of the worksheet. I would like to apply the filter by pair of columns.


    [Desired effect] Filtering only each pair on columns and removing references to other entries identified as Amber or Green.
    COLUMN A..........................COLUMN B.............COLUMN C...........COLUMN D .......... COLUMN E........ COLUMN F
    RED...................................Test 1....................RED...................Test 6.................. RED............. Test 8
    RED...................................Test 2....................RED...................Test 11


    [All other entries hidden/removed using filter - for example AMBER and GREEN entries in Columns A and B, C and D and E and F]

    I'm not too sure if any of the above is possible, or if it makes sense the way I have put this across. I didn't really explain very well at the start of my question as I referred to Auto sort when I should may be have mentioned filtering out certain information as well.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Using VBA / Macro to autosort pairs of connecting columns and rows?

    You cannot put multiple sets of data in the same row and hide one "set" and not the entire row.

+ Reply to Thread

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