+ Reply to Thread
Results 1 to 7 of 7

Using MAX function with some blank values in userform

  1. #1
    Registered User
    Join Date
    06-10-2014
    Posts
    15

    Using MAX function with some blank values in userform

    Hello,

    I am trying to use the max function that returns the maximum value stored in 12 different comboboxes and stores it in a variable r. The boxes are named cb1, cb2, cb3, etc. The line of code I have is

    r = WorksheetFunctions.Max(me.cb1.value, me.cb2.value, [...etc...], me.cb12.value)

    but this is giving me run time error 1004, unable to get the max property of the WorksheetFunction class. I believe this is because the default value of the comboboxes are blank. I'd like to keep the default values to be blank, so is there a way to deal with this?

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2411
    Posts
    26,673

    Re: Using MAX function with some blank values in userform

    There might be a better way but this is the first one I thought of that I know works:

    Please Login or Register  to view this content.
    Note that "Me." is optional, because any reference is automatically assumed to be to a component of "Me.". Also note that Value is the default attribute of ComboBox so that is also optional.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    06-10-2014
    Posts
    15

    Re: Using MAX function with some blank values in userform

    Jeff,

    That solution did not work. I am still receiving the same run time error. Do you have any alternate suggestions?

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2411
    Posts
    26,673

    Re: Using MAX function with some blank values in userform

    It worked in my file. If you attach yours I might be able to help further.

  5. #5
    Registered User
    Join Date
    06-10-2014
    Posts
    15

    Re: Using MAX function with some blank values in userform

    I have attached a spreadsheet with the userform to this post. You'll need to go into the VBA editor to see it. The spreadsheet it's a part of has some confidential data so I had to separate the form but I don't think it will make a difference. The code in question is in the topmost combobox labelled "# of releases" beneath the lengthy case setup. While the userform initializes fine, it crashes when I try to change the value in that combobox. Book4.xlsm

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2411
    Posts
    26,673

    Re: Using MAX function with some blank values in userform

    Your comboboxes return a value of " " (2 spaces) when there has been no selection. In my test they returned "" (null string).

    When I modified your code to use this line of code it worked.


    Please Login or Register  to view this content.
    I would also suggest splitting the line up for readability

    Please Login or Register  to view this content.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2411
    Posts
    26,673

    Re: Using MAX function with some blank values in userform

    Thanks for the rep! If your question has been answered please mark your thread as "Solved" so that members will know by looking at the thread title that your problem is solved. Go to the menu immediately above your first post to the thread and click on Thread Tools. From the dropdown menu select "Mark this thread as solved..."

+ 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. Testing for blank values from a function
    By colonelbobaloo in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-23-2013, 08:03 PM
  2. [SOLVED] Sum function not working on time values from userform
    By lsteinbach in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-05-2013, 07:45 PM
  3. Replies: 2
    Last Post: 03-01-2011, 05:13 PM
  4. Replies: 5
    Last Post: 12-02-2009, 08:02 AM
  5. Array Function - ignore blank values
    By gillemi in forum Excel General
    Replies: 6
    Last Post: 06-13-2006, 04:10 AM

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