LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Changing values in an array using for each

I have a 2D array, say it is 20 x 30 and I want to change any zero values to
say 10. I would have expected the following smaller example to work but it
only changes the value for 'v' rather than the value of the array members.

Sub test()
Dim ar1(1, 1) As Variant, v As Variant
ar1(0, 0) = 1
ar1(0, 1) = 1
ar1(1, 0) = 1
ar1(1, 1) = 1
For Each v In ar1
v = 2
Next
End Sub

I can do it with the following but I was surprised to find for each did not
seem to work as I would have expected

Sub test()
Dim ar1(1, 1) As Variant, v As Variant, i, j
ar1(0, 0) = 1
ar1(0, 1) = 1
ar1(1, 0) = 1
ar1(1, 1) = 1
For i = 0 To UBound(ar1, 1)
For j = 0 To UBound(ar1, 2)
ar1(i, j) = 2
Next
Next
End Sub


Andrew
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Prevent cell/array references from changing when altering/moving thecell/array nme Excel Discussion (Misc queries) 1 September 19th 08 01:53 PM
Array: Counting multiple values within array Trilux_nogo Excel Worksheet Functions 4 April 16th 07 03:12 AM
changing values in one column based on values in another? QuickLearner[_18_] Excel Programming 1 July 10th 06 04:18 PM
Use array to return array of values Brad Excel Worksheet Functions 2 March 30th 06 05:58 PM
Convert values in a variant array to integer values Graham McNeill Excel Programming 1 November 13th 04 12:47 AM


All times are GMT +1. The time now is 02:27 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"