+ Reply to Thread
Results 1 to 6 of 6

Type-Mismatch on UBOUND(Array)

  1. #1
    Forum Contributor codeslizer's Avatar
    Join Date
    05-28-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003 - 2010
    Posts
    245

    Type-Mismatch on UBOUND(Array)

    Hey Guys,

    I have a dynamic named range called "Test1" which contains a list of headers for a table am trying to create through macro. Am able to assign the dynamic range to the array named "dynArr" but just getting stuck at a point where am trying to get the upper bound of the array. My code works fine if I replace
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.
    Following is my code.

    Please Login or Register  to view this content.
    Please show me some light..
    cOdEsLiZeR - Back after a long break.. Let's sLiZe some more cOdEs!!

  2. #2
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Type-Mismatch on UBOUND(Array)

    You are dealing with 1D and 2D arrays in your code.

    Range >> array = 2D array

    This creates a 1D array
    Please Login or Register  to view this content.
    This creates a Range (not an array)
    Please Login or Register  to view this content.
    What you need is something like this (Untested):
    Please Login or Register  to view this content.
    dynArr is now a 1D array because Application.transpose converts the 2D array (the range) to a 1D array

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  3. #3
    Forum Contributor codeslizer's Avatar
    Join Date
    05-28-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003 - 2010
    Posts
    245

    Re: Type-Mismatch on UBOUND(Array)

    Thank you Abousetta!

    Though there were minor bugs in the code, I was able to get what you were trying to make me understand. Thank you very much! :D But I must say, the last part..

    dynArr is now a 1D array because Application.transpose converts the 2D array (the range) to a 1D array
    It still gives the result in 2D array. As I got "Subscript out of range" error when I tried getting the element using dynArr(i) statement.
    Following is my working code:
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor codeslizer's Avatar
    Join Date
    05-28-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003 - 2010
    Posts
    245

    Talking Re: Type-Mismatch on UBOUND(Array)

    Oops.. please use the following code. I have put the codes after Exit Sub for my testing purpose.. included unknowingly..

    Please Login or Register  to view this content.

  5. #5
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Type-Mismatch on UBOUND(Array)

    Range("Test1") is a range not an array

    This works fine (slightly modified from your approach):

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor codeslizer's Avatar
    Join Date
    05-28-2013
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003 - 2010
    Posts
    245

    Re: Type-Mismatch on UBOUND(Array)

    Yep! That's Right. Its not an array. I have been using it to get the address of the elements in the named range.
    the last part in the same statement was to test if the values were really stored in the array.

    Thanks for drilling down to my codes again :D

+ 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 TY] Type mismatch using array and DDL
    By futurespec in forum Excel Programming / VBA / Macros
    Replies: 32
    Last Post: 07-02-2012, 09:34 AM
  2. Type Mismatch: array or user defined type expected
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-06-2006, 10:45 AM
  3. Array problem: Key words-Variant Array, single-element, type mismatch error
    By davidm in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-09-2005, 01:54 AM
  4. Array problem: Key words-Variant Array, single-element, type mismatch error
    By davidm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-08-2005, 12:30 AM
  5. [SOLVED] Help: Compile error: type mismatch: array or user defined type expected
    By lvcha.gouqizi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2005, 05:05 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