+ Reply to Thread
Results 1 to 3 of 3

getting #VALUE error on the cell ith the function

  1. #1
    Registered User
    Join Date
    11-29-2020
    Location
    india
    MS-Off Ver
    2021
    Posts
    92

    getting #VALUE error on the cell ith the function

    i keep getting #VALUE! error on the cell...

    my code is
    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: getting #VALUE error on the cell ith the function

    The cause of the #VALUE! error is that your function throws runtime errors on x.Value.

    FIRST, there's absolutely no good reason not to declare C or x along with Result and pc. More fundamentally, there's no good reason not to begin all VBA code modules with Option Explicit to oblige you to declare all variables. Had you done so, you would have discovered that Split(pc, ",") produces an array of strings. You can iterate through arrays with For Each x . . ., but that x loop variable would hold a string value rather than a Range object. In brief, x doesn't have a .Value property.

    Next time, when UDFs return #VALUE! errors, add the statement

    Stop

    just after variable declarations. That will pause execution at the beginning of the function. Then you can step through the function in Debug mode, and the VBA Editor will show you useful error messages as runtime errors occur.

    That said, there are problems in your function. Replace all x.Value with x, and your function would only ever return "" or "GREEN" because each of the 3 If blocks inside the For Each x . . . block performs the same test, x = SL. Presumably you mean the 2nd to compare x to ST and the 3rd to SB. Even then, why iterate through all of ANALYSIS!A3:A11? Just use Application.Match to find the bottommost instance of chkpc in ANALYSIS!A3:A11, then use the corresponding cell in ANALYSIS!H3:H11 for the Split(...) call.

    Then there's generality and recalculation dependence. As written, if you're using this function in cell formulas, if cell values change in ANALYSIS!A3:A11 or ANALYSIS!H3:H11, cell formulas calling this function won't update via standard (minimal) automatic recalculation because Excel won't realize those formulas depend on those ranges because those ranges aren't function arguments.

  3. #3
    Registered User
    Join Date
    11-29-2020
    Location
    india
    MS-Off Ver
    2021
    Posts
    92

    Re: getting #VALUE error on the cell ith the function

    yup it orked...changingx.vaue to x worked...thank u so much

+ 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. index function error using match function to get data from a cell in an array
    By mabildgaard in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-17-2013, 02:21 AM
  2. IF statement returns 1004 error when trying to add function to a cell using VBA
    By chairmaker in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-06-2013, 03:03 PM
  3. Using Multiple =IF(FIND( Function in One Cell Error
    By ReallyCoolGuyYeah in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-04-2013, 04:21 PM
  4. [SOLVED] Nested Function & Offset Cell ERROR
    By DDM64 in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 01-25-2013, 04:23 PM
  5. Replies: 3
    Last Post: 01-22-2013, 05:38 AM
  6. [SOLVED] Getting an error when trying to call a function from a sub, with string value of cell
    By RebelScum in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-21-2012, 06:21 AM
  7. [SOLVED] If function when multiplying by a none-value cell (VALUE! error)
    By Leif Magnus in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 10-04-2012, 02:17 PM
  8. Using a macro to put a function in a certain cell (runtime error 1004)
    By Juhanen II in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-30-2007, 10:29 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