+ Reply to Thread
Results 1 to 8 of 8

Assigning a 2D Array to a bigger size range results in "#N/A" in the uncovered elements

  1. #1
    Registered User
    Join Date
    10-19-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    12

    Assigning a 2D Array to a bigger size range results in "#N/A" in the uncovered elements

    I have a 2D array that is being assigned to an Excel range. The range has bigger size than the array:

    Please Login or Register  to view this content.
    This will result in #N/A in the range where the 2D array did not cover, check the attached image.

    A way to work around that is to downsize the range area temporarily, do the assignment then upsize it again, however, I wanted to open this for discussion for better solutions before I implement this to see if there are better solutions.

    Ideas?
    Attached Images Attached Images

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Resize the array using ReDim Preserve.
    If posting code please use code tags, see here.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Assigning a 2D Array to a bigger size range results in "#N/A" in the uncovered element

    Hi,

    Something like the following perhaps

    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    10-19-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Assigning a 2D Array to a bigger size range results in "#N/A" in the uncovered element

    But the array is strongly typed, what values would I use to fill the newly created elements with ReDim?

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Assigning a 2D Array to a bigger size range results in "#N/A" in the uncovered element

    Just realised you need to resize both dimensions, so you can't use Redim Preserve.

    You don't need to downsize the range though.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-19-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Assigning a 2D Array to a bigger size range results in "#N/A" in the uncovered element

    A quick and dirty way is as follows, I am not sure about the performance hit compared to downsizing then upsizing (as I want to preserve the original range size)

    Please Login or Register  to view this content.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Assigning a 2D Array to a bigger size range results in "#N/A" in the uncovered element

    The code I posted neither upsizes or downsizes.

  8. #8
    Registered User
    Join Date
    10-19-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Assigning a 2D Array to a bigger size range results in "#N/A" in the uncovered element

    Quote Originally Posted by Norie View Post
    Just realised you need to resize both dimensions, so you can't use Redim Preserve.

    You don't need to downsize the range though.
    Please Login or Register  to view this content.
    Thank you, that solves the issue

+ 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