R
Revolvr
Hi all,
I have some VBA code that needs to manipulate data in a named range. In the
code I use this:
mydata = Range("MyData")
This is normally a range of cells, so "mydata" becomes an array, so I can do
something like:
a = mydata(ir, ic)
Where ir and ic are integers representing the row and column in the range.
(Note that there is no DIM statement for mydata).
However, if per chance the range MyData contains only 1 cell I get a "Type
Mismatch" error on the above code because the variant mydata is no longer an
array, but a single parameter.
So this means I have to put a check in my code like this:
if ( Range("MyData").count = 1 ) then
a = mydata
else
a = mydata(ir,ic)
end if
I would rather not do this "IF" test each time. Are there some better ways
to reference values in the MyData range?
Thanks,
-- Rev
I have some VBA code that needs to manipulate data in a named range. In the
code I use this:
mydata = Range("MyData")
This is normally a range of cells, so "mydata" becomes an array, so I can do
something like:
a = mydata(ir, ic)
Where ir and ic are integers representing the row and column in the range.
(Note that there is no DIM statement for mydata).
However, if per chance the range MyData contains only 1 cell I get a "Type
Mismatch" error on the above code because the variant mydata is no longer an
array, but a single parameter.
So this means I have to put a check in my code like this:
if ( Range("MyData").count = 1 ) then
a = mydata
else
a = mydata(ir,ic)
end if
I would rather not do this "IF" test each time. Are there some better ways
to reference values in the MyData range?
Thanks,
-- Rev