Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() I should add that I know the examples do not change zero values to 10 but if they changed them at all then I would have a method I can use. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
An array is not a collection, so it doesn't work like a collection.
-- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "Andrew Hall NZ" wrote in message ... 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Prevent cell/array references from changing when altering/moving thecell/array | Excel Discussion (Misc queries) | |||
Array: Counting multiple values within array | Excel Worksheet Functions | |||
changing values in one column based on values in another? | Excel Programming | |||
Use array to return array of values | Excel Worksheet Functions | |||
Convert values in a variant array to integer values | Excel Programming |