+ Reply to Thread
Results 1 to 4 of 4

Storing UBound value in an integer variable.

  1. #1
    Registered User
    Join Date
    04-15-2019
    Location
    Manila, Philippines
    MS-Off Ver
    2016
    Posts
    39

    Storing UBound value in an integer variable.

    I have no idea at all why is this not working. Can someone explain? I am at a total loss at this one.

    Please Login or Register  to view this content.
    When I use Test1 function to input an array of cells it always chucks out a VALUE error. Say I selected B1:B4, instead of giving the result of 4 as expected, just a value error.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Storing UBound value in an integer variable.

    When I see this, I expect to see that arraytest is probably typed as a Range object variant rather than a variant containing a VBA array. Run this modification (all I did was add a stop statement)
    Please Login or Register  to view this content.
    When it gets to the Stop and brings up debug mode, look in the locals window or set a watch for Typename(arraytest) or add a debug.print typename(arraytest) or other strategy to see what type arraytest is.

    What are you trying to get from the Ubound() function? Usually I am trying to get a count of how many cells are in the range object, so I often use val=arraytest.Count instead of UBound.

    Does arraytest need to be able to handle both range object and VBA array inputs? You might need a block IF() at the top of the procedure that detects what data type arraytest is and choose the appropriate course of action.

    I sometimes find it valuable to be more specific when typing input arguments. In this case, if you only ever plan to pass Excel ranges to the function, type arraytest as a Range object (arraytest as Range), which will make it more clear to you in your code that arraytest is not a VBA array.

    In short, I think the problem is a data type problem -- UBound cannot tell what the upper index of an Excel range is. The final solution to the problem depends on exactly how you need the procedure to work with arraytest.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Storing UBound value in an integer variable.

    You're passing a range, not an array, so you need:

    Please Login or Register  to view this content.
    Rory

  4. #4
    Registered User
    Join Date
    04-15-2019
    Location
    Manila, Philippines
    MS-Off Ver
    2016
    Posts
    39

    Re: Storing UBound value in an integer variable.

    Got it from both of you. Thanks!

+ 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] Storing a variable for later reference
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-29-2017, 11:52 AM
  2. [SOLVED] VBA Code to convert one variable as an Integer to a new variable as a month name
    By rvgray in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-01-2017, 03:18 AM
  3. storing a string into a variable
    By reeceponse in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-29-2009, 12:16 PM
  4. Storing a value in a variable for use at a later date.
    By Neil07979 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-20-2008, 07:55 AM
  5. [SOLVED] Storing a value to variable
    By CLamar in forum Excel General
    Replies: 0
    Last Post: 06-16-2006, 11:50 AM
  6. [SOLVED] Storing value in a variable from a cell
    By Saadi in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-08-2005, 10:06 AM
  7. [SOLVED] Storing value in a variable from a cell
    By Saadi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-07-2005, 07:06 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