+ Reply to Thread
Results 1 to 8 of 8

sorting columns based on row criteria, with variable number of columns

  1. #1
    Registered User
    Join Date
    02-21-2014
    Location
    Houston
    MS-Off Ver
    Excel 2010
    Posts
    21

    sorting columns based on row criteria, with variable number of columns

    I'm trying to put some macro buttons on a template that teachers use to analyze testing data. The template has a column for each question. The questions always begin on column C, but may range to any column depending on the number of questions on the test. The buttons would sort the questions by different rows (question #, % correct, type of question, etc.)

    The following recorded macro does what I want, except, the range will not always be what it recorded here. It may be from C:BD or from C:Z or whatever else. How can I adapt the code to adjust for whatever number of columns there might be?

    I would also like to have a similar command for another section of columns in the template (from BL:DE in the attached sample), but in that case both the beginning and ending columns would be variable. That section would always begin two columns to the right of the "Total Tested" columns.

    A sample file is attached and linked to below.


    Please Login or Register  to view this content.
    Attachment 341532

    https://drive.google.com/file/d/0B0N...it?usp=sharing

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

    Re: sorting columns based on row criteria, with variable number of columns

    Maybe:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-21-2014
    Location
    Houston
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: sorting columns based on row criteria, with variable number of columns

    I very much appreciate the effort, but it doesn't seem to do it. On the attached file, the code you provided seems to include in the sorting range the black columns to the right of the questions. It should stop at the last question (after which there currently exists a thin blank column), as if one was hitting CTRL+Shift+Right Arrow to select from C to the end. Any possibilities there? Thank you again.

  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: sorting columns based on row criteria, with variable number of columns

    I can't open the attachment. I get a message saying it is invalid?

  5. #5
    Registered User
    Join Date
    02-21-2014
    Location
    Houston
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: sorting columns based on row criteria, with variable number of columns

    Hopefully this attachment works better. There's also a google drive link in the original post.

    test view sample1.xlsx

  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: sorting columns based on row criteria, with variable number of columns

    If your format offsets 8 each time between questions then maybe:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-21-2014
    Location
    Houston
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: sorting columns based on row criteria, with variable number of columns

    Sorry, was off this project for a few days, and just saw your post. It works perfectly, selecting either range perfectly no matter the number of columns, and I've been able to adapt it for several similar commands. Thanks so much for solving this question.

    Would it be adaptable to hide columns according to a certain criteria? For example, in the range that is defined as x in your code above, let's say I don't want to sort it, but rather hide all columns where the value of the cell in Row 10 doesn't contain [R].

    I had some similar code from another setting that did this. It was:
    Please Login or Register  to view this content.
    Here is my attempt to adapt your code and the other to accomplish what I mentioned above, but it doesn't quite go:

    Please Login or Register  to view this content.
    Any thoughts, or should I start a new thread?

  8. #8
    Registered User
    Join Date
    02-21-2014
    Location
    Houston
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: sorting columns based on row criteria, with variable number of columns

    I got the basic principle to work with the following code:

    Please Login or Register  to view this content.
    But instead of "m5" in the third to last line, I would want it to recognize [R] with wild cards on either side of it, but *[R]* doesn't work.

    Any ideas? I know I could get it to work by creating a helper row that just had the [R], but it would be nice to avoid that extra step.

+ 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] Variable column range, based on current selection, for sorting columns
    By kshelmidine in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-16-2014, 11:46 AM
  2. Sorting data into columns based on criteria
    By loonyhat in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 12-31-2013, 02:17 PM
  3. Replies: 0
    Last Post: 05-15-2013, 09:18 AM
  4. Formula based on variable number of non-adjacent columns
    By abousetta in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-19-2010, 04:22 AM
  5. [SOLVED] Chart based on variable number of columns
    By Scott Hamilton in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 06-05-2005, 09:40 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