+ Reply to Thread
Results 1 to 4 of 4

Problem using the Large function in VB

  1. #1
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Problem using the Large function in VB

    I use this macro to rank the 15 highest numbers in a range of values.

    Please Login or Register  to view this content.
    It works fine if the cell contain a value i.e. 18298.9 but if it’s a formula like "D4=C4*B4"
    I get “Run-time error ‘91’: Object variable or With block variable not set”

    I’ve tried to add “LookIn:=xlFormulas” and “LookAt:=xlPart” but I still get the same error message.

    Of course I could add a helper column converting formulas to values but I was hoping to find a solution as the Large function works with formulas in a “normal” Excel environment.

    Alf

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Problem using the Large function in VB

    Alf,

    I'm not sure why you wouldn't just use the formula, but here's a modified version of your macro. The .Find method needs to use xlValues to find values resulting from formulas. I also included a change to provide unique ranking just in case there are any duplicate numbers in the top 15:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Problem using the Large function in VB

    Alf,

    Alternate, condensed version using the macro to input the formula, and then replacing the formula with its resulting values:
    Please Login or Register  to view this content.

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Problem using the Large function in VB

    Hi

    Thanks for help. I've used your second macro as it was short & compact.

    I'm not sure why you wouldn't just use the formula
    I wanted to place ranking number next to the appropriate value and did not manage to solve that just by using the formula.

    Regards

    Alf

+ 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