+ Reply to Thread
Results 1 to 4 of 4

Simple way to initialize an array or a range

  1. #1
    Registered User
    Join Date
    12-29-2011
    Location
    San Diego, Ca.
    MS-Off Ver
    Excel 2007
    Posts
    60

    Simple way to initialize an array or a range

    Trying to find a quick and dirty way to initialize an array to 0 values. Using arrays and the Redim statement does the trick but for learning sake I tried to do this with the resize method on ranges which doesn't work. Assume cells A1,B1,A2 and B2 have non-zero values. Here is the code.

    Please Login or Register  to view this content.
    Thanks.
    Last edited by jeffreybrown; 01-11-2020 at 10:47 PM. Reason: Please use code tags!

  2. #2
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,482

    Re: Simple way to initialize an array or a range

    you don't need the select statement. that is causing the problem this time.
    the select only affects the selection in the worksheet but does not change the actual size of the array (then you need Redim)

    Please Login or Register  to view this content.
    ___
    sidenote: please use codetags around code on your next post (that is a forum-rule / requirement), it is the #-icon

  3. #3
    Registered User
    Join Date
    12-29-2011
    Location
    San Diego, Ca.
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Simple way to initialize an array or a range

    Thanks. Too funny. I have done my best to avoid using activate and select in all VBA code and only did it here to make sure I could see that the array was expanded. Hoisted by my own Petard.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    Hi !

    You just need a single codeline : [A1:B2].Resize(3).Value2 = 0 !

    If the resize part never changes so obviously just with [A1:B3].Value2 = 0

+ 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. How to 'Initialize 2D array with 81 empty grids (nx = 9, ny = 9)' in VBA?
    By sultanoflondon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-15-2015, 05:25 AM
  2. Simple User form initialize and close
    By T 520 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-09-2015, 02:47 PM
  3. Initialize array from cell values in a column...
    By Bishonen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-22-2013, 08:03 PM
  4. How do I declare and initialize an array?
    By Corey R. in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-23-2009, 05:04 PM
  5. Initialize or Assign Array Values
    By apka in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-11-2008, 07:04 PM
  6. initialize an array to 0
    By kdp145 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-15-2006, 04:25 PM
  7. Initialize an array
    By Kleev in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-01-2005, 02:15 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