+ Reply to Thread
Results 1 to 15 of 15

max number of a spreadsheet but exclude 3 numbers

  1. #1
    Registered User
    Join Date
    01-04-2010
    Location
    Walla Walla, WA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    9

    max number of a spreadsheet but exclude 3 numbers

    hi

    i have a worksheet filled with numbers in each cell (the worksheet might have a total of 150 rows and 150 columns of numbers).

    the numbers typically range from 1-3 or 1-9 or 1-150.

    however, there are also multiple 997, 998, and 999 numbers in the cells.

    i need to identify the highest number in the worksheet that is not 997, 998, or 999.

    can someone help?

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: max number of a spreadsheet but exclude 3 numbers

    You can use an array formula like this

    =MAX(IF(range<997,range))

    confirmed with CTRL+SHIFT+ENTER

    or a non-array version

    =LARGE(range,COUNTIF(range,">=997")+1)

    either way replace range with your specific range......

  3. #3
    Registered User
    Join Date
    01-04-2010
    Location
    Walla Walla, WA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    9

    Re: max number of a spreadsheet but exclude 3 numbers

    shoot. i'm kind of a newbie so i'm clearly doing something wrong.

    here's the current code (but it returns the maximum value which will be 997, 998 or 999):

    Please Login or Register  to view this content.
    here are the ways i tried to implement your suggestion (replacing 'get max above); all of them show as red font meaning there is an error in them:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    01-04-2010
    Location
    Walla Walla, WA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    9

    Re: max number of a spreadsheet but exclude 3 numbers

    hmm. maybe the problem is on the worksheet itself.

    this is a complicated spreadsheet that two different people have worked on prior to/in addition to me.

    when i select what should be r4c4:r10c10, i get this:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-04-2010
    Location
    Walla Walla, WA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    9

    Re: max number of a spreadsheet but exclude 3 numbers

    i was able to do this on the worksheet itself but i still don't see how to do it excel vba code.

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

    Re: max number of a spreadsheet but exclude 3 numbers

    To use DLL's example,
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Registered User
    Join Date
    01-04-2010
    Location
    Walla Walla, WA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    9

    Re: max number of a spreadsheet but exclude 3 numbers

    shg and ddl

    thanks but still can't get it to work.

    i'm attaching a spreadsheet with just the prefs page (none of the other modules/forms are in it).

    would you be able to add in the code to the spreadsheet (as a vba module) and post back to this page?

    jim
    Attached Files Attached Files
    Last edited by hansonjb; 01-04-2010 at 10:42 PM.

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

    Re: max number of a spreadsheet but exclude 3 numbers

    Adding a Macro to a Code Module
    1. Copy the code from the post
    2. Press Alt+F11 to open the Visual Basic Editor (VBE)
    3. From the menu bar in the VBE window, do Insert > Module
    4. Paste the code in the window that opens
    5. Press Alt+Q to close the VBE and return to Excel

    Once you do that, you must save the workbook as an .xlsm (macro-enabled) workbook.

    But why do you want to do this with VBA rather than just a formula?
    Last edited by shg; 01-05-2010 at 11:56 AM.

  9. #9
    Registered User
    Join Date
    01-04-2010
    Location
    Walla Walla, WA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    9

    Re: max number of a spreadsheet but exclude 3 numbers

    i have pasted in the code as you explain and it doesn't work. i get error messages. i tried in multiple ways to adjust it and none worked.

    in the previously attached spreadsheet, which i have changed on my computer to an .xlsm file--i get a runtime 13 error, type mismatch.

    i suppose i could do this as a formula on the page but i am worried (in fact, i'm almost certain) that other code in the program erases all data/functions on the worksheet (when you begin working on it, before you enter the data).

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

    Re: max number of a spreadsheet but exclude 3 numbers

    See attached.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    01-04-2010
    Location
    Walla Walla, WA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    9

    Re: max number of a spreadsheet but exclude 3 numbers

    thank you.

    i'm still having issues getting this working in the spreadsheet itself but this gives me a good start.

  12. #12
    Registered User
    Join Date
    01-04-2010
    Location
    Walla Walla, WA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    9

    Re: max number of a spreadsheet but exclude 3 numbers

    sorry for the hassle.

    the problem appears to be because the spreadsheet uses the r1c1 format.

    i've tried to change the formula to Cells (2,2),Cells(30,30) and i just get errors.

    can you repost the file with the code but in r1c1 format?

    (why r1c1 format? the person who originally did the spreadsheet uses that to do the most complex parts of the spreadsheet and so i need to stick with it).

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

    Re: max number of a spreadsheet but exclude 3 numbers

    Tools > Options > General, untick R1C1 reference style, then run the sub.

  14. #14
    Registered User
    Join Date
    01-04-2010
    Location
    Walla Walla, WA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    9

    Re: max number of a spreadsheet but exclude 3 numbers

    well, i need something in the code itself since i need to make these kind of calculations (max excluding 3 numbers) in various parts of the code.

    one way i now see to do it is (where i switch to a1 style, do the code, and then switch back to the r1c1 style at the end of the code):

    Please Login or Register  to view this content.

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

    Re: max number of a spreadsheet but exclude 3 numbers

    Here's another way:
    Please Login or Register  to view this content.

+ 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