+ Reply to Thread
Results 1 to 6 of 6

UDF not handling Numbers stored as text

  1. #1
    Forum Contributor
    Join Date
    01-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    100

    UDF not handling Numbers stored as text

    Please Login or Register  to view this content.

    I got this UDF from a Forum Guru here. And it has worked perfectly up til now. It seems the original version doesn’t handle numbers stored as Text. The IsNumeric line gives a “false positive” for numbers stored as text and tries to handle it.
    The column field on the pivot table is “JobCode”. The data in this field is Numbers stored as text. When I run the function thru the debugger the “JobCode” is handled by the line
    Please Login or Register  to view this content.
    The result is “JobCode”, 402

    Where I think it should be handled by the line
    Please Login or Register  to view this content.
    so the result would be “JobCode”, “402”

    I attempted to fix the problem by replacing this

    Please Login or Register  to view this content.
    with this

    Please Login or Register  to view this content.
    If the Filter = “123” then it would concatenate the two strings and result in “1230” and then Filter.Value + ”0” would not = Filter.Value and it would be handled as a string.
    On the other hand if some other Filter was 123, attempting to concatenate a string “0” to it would result in 123 and it would be handled as a Number .

    When I run this it runs down to the line
    Please Login or Register  to view this content.
    And then starts over at the strFormula line and changes the strDataField from “CountofPeople” to “People”. “CountofPeople” is the field name and in the table is actually “Sum of CountofPeople”. The first time thru it uses the correct version “CountofPeople” and then kicks back to the beginning and changes to "People" and it runs thru the code fine and handles the numbers stored as text fine. But still results in an error due to the incorrect DataField. Any idea why that line is kicking the code back to the beginning?
    Thanks

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,280

    Re: UDF not handling Numbers stored as text

    I currently only have forum access on my phone so can't fix the code now but it should be easy enough to use TypeName to test for string parameters first before using the IsNumeric and IsDate tests.
    Remember what the dormouse said
    Feed your head

  3. #3
    Forum Contributor
    Join Date
    01-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    100

    Re: UDF not handling Numbers stored as text

    Rory, Thanks Again! I replaced this...

    Please Login or Register  to view this content.
    with this...

    Please Login or Register  to view this content.
    and no more errors.
    Thanks

  4. #4
    Forum Contributor
    Join Date
    01-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    100

    Re: UDF not handling Numbers stored as text

    I spoke too soon... That only works when I point it directly at the pivottable. If I replace the JobCode with a cell reference it fails.
    If I use a GETPIVOTDATA( and point JobCode to cell A1 which contains '605 it works fine.
    If I use datafrompivot, it fails.

    Please Login or Register  to view this content.
    I am stepping thru the Function and when it gets to JobCode it steps down to

    Please Login or Register  to view this content.
    then on F8 it skips down to
    Please Login or Register  to view this content.
    and returns 605

    I have looked at the cell format and it is formatted as text.
    It works fine when used in the GETPIVOTDATA function,
    and I typed
    Please Login or Register  to view this content.
    in the immediate window and it returned String.

    I am not sure what to try next.

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,280

    Re: UDF not handling Numbers stored as text

    TypeName(Filters(n + 1)) is probably returning "Range". Try using an intermediate variant variable:
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    01-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    100

    Re: UDF not handling Numbers stored as text

    That did it! Thanks again, Rory.

+ 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. [SOLVED] Marco to convert numbers stored as text to numbers and dates stored as text to numbers
    By a2424 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-22-2014, 10:19 AM
  2. [SOLVED] Convert all numbers stored as text or custom formatted to numbers &no decimals - 40 sheets
    By synses in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-19-2013, 01:46 AM
  3. Replies: 2
    Last Post: 10-22-2009, 02:50 PM
  4. [SOLVED] VLOOKUP should compare numbers stored as text to plain numbers.
    By VLOOKUP - Numbers stored as text in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-31-2006, 12:55 PM
  5. Convert numbers stored as text to numbers Excel 2000
    By Darlene in forum Excel General
    Replies: 6
    Last Post: 01-31-2006, 04:10 PM

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