Results 1 to 4 of 4

Simple way to initialize an array or a range

Threaded View

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

    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.

    Sub test()
    
    Dim rgn As Range
    
        Set rgn = Range("A1:B2")
        rgn.Resize(3, 2).Select           'This does select the larger range of 3 rows and 2 columns
        rgn.Value = 0                        'This only sets the cells A1,B1,A2,B2 to zero but not A3 and B3.  Why?
    
    End Sub
    Thanks.
    Last edited by jeffreybrown; 01-11-2020 at 10:47 PM. Reason: Please use code tags!

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