+ Reply to Thread
Results 1 to 10 of 10

Only Sort Cells if Cell Values are Greater than 0

  1. #1
    Forum Contributor
    Join Date
    07-03-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    139

    Only Sort Cells if Cell Values are Greater than 0

    I am working on a Golf League score sheet, and each week there may be a different amount of players that play. I have a weekly worksheet (attached) that contains the full list of golfers that had played that week and I only want to sort the columns for those golfers who have a score greater than 0 (this would be the ones who played that week). You can see that in week 1 I had more players than in week 2. So in my weekly worksheet I sort these sub grids by Score first. However I ONLY want to sort the rows that have a score greater than 0. Can this be done in VBA or am I stuck doing this manually every week?

    Week1.PNG
    Week2.PNG
    Last edited by Leith Ross; 05-15-2014 at 03:14 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Only Sort Cells if Cell Values are Greater than 0

    Are you just saying that you want the 0's at the bottom? It looks like youre not sorting on anything in particular, this is just a search descending will give you what you want but the scores desceding?
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Forum Contributor
    Join Date
    07-03-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: Only Sort Cells if Cell Values are Greater than 0

    I will be sorting on scores Ascending so the best score is at the top, however if I sort the entire sub-grid, all the players who did not golf that day (0 for score) will be at the top, which is what I do not want to occur. I also sort of some of the other columns after score but once I figure this part out, I can get the rest.

    Thank You

  4. #4
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Only Sort Cells if Cell Values are Greater than 0

    You could do it with a simple sort descending on the full table, this will give you what you want with the top score down and all the 0's at the bottom.

    Then you'll need to find the first 0, so Application.WorksheetFunction.Match("0",range("a:a"),false) and pass this to a row number variable.

    You can then use, row 1 to row 1st 0 and then do sorting on the other fields.

    So you say, have 25 players, 5 didnt golf

    1st Operation sort all 25 rows descending by score.

    2nd Operation, find the 1st 0, row 21

    3rd Operation, sort on range A1:A21, what every you want.

  5. #5
    Forum Contributor
    Join Date
    07-03-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: Only Sort Cells if Cell Values are Greater than 0

    very slick, I will give this a shot and reply back to let ya know how that went. Thanks for the tip Nathan. I'm at work now, so it may be a while before I can "play"

  6. #6
    Forum Contributor
    Join Date
    07-03-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: Only Sort Cells if Cell Values are Greater than 0

    I have the following code entered in to try to retrieve the cell address of the first occurrence of 0 but I am getting the Unable to get the Match property of the WorksheetFunction class error

    Please Login or Register  to view this content.
    SRng is a public string variable

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Only Sort Cells if Cell Values are Greater than 0

    You could just add a column and sort on that:

    =if(score<>0, score, 999)
    Entia non sunt multiplicanda sine necessitate

  8. #8
    Forum Contributor
    Join Date
    07-03-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: Only Sort Cells if Cell Values are Greater than 0

    adding a column isn't going to work for the person I am helping with project, thanks for tip though

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Only Sort Cells if Cell Values are Greater than 0

    If you're planning to use code, as it appears, then you can do it in code, and clear the helper formula when you're done.

  10. #10
    Forum Contributor
    Join Date
    07-03-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: Only Sort Cells if Cell Values are Greater than 0

    I am getting close, I have the following now that gives me the $D$21 for SAmnt variable (which is now a string variable), and D21 is the FIRST cell that has a 0 listed. NOW what I want this to do is to drop the $'s and offset by one row, meaning the result of SAmnt I am looking for is D20.

    Please Login or Register  to view this content.
    Any thoughts?

+ 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: 3
    Last Post: 09-29-2010, 01:30 AM
  2. Sum cells in range with values greater than 2
    By henneman in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-20-2010, 02:35 PM
  3. return only cells with values greater than 0
    By Sprain Brain in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 02-02-2010, 05:28 AM
  4. Replies: 3
    Last Post: 12-15-2009, 04:06 PM
  5. Check for values greater than zero in 2 cells
    By spartacus_33 in forum Excel General
    Replies: 4
    Last Post: 11-03-2008, 07:39 PM

Tags for this Thread

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