View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Fastest way to reset to zero an array

Do you mean array or range? I'm confused about your use of "cell" in your
question.

But I'd start by looking at Erase in VBA's help (for an array--not for a range):

Dim myArr(1 To 3, 1 To 2) As Long
Dim iCtr As Long
Dim jCtr As Long

For iCtr = 1 To 3
For jCtr = 1 To 2
myArr(iCtr, jCtr) = iCtr * jCtr
Next jCtr
Next iCtr

Erase myArr



Charles wrote:

Hello

This is a relatively simple question but I can't find it on google
group. What is the fastest way to reset an array to zero (or the value
by default). (in this case, performance is key, every micro-second
counts!)

Intuitively, I would say that going through every single cell and
setting it to zero must be under-efficient, as VBA has to interpret a
let more instructions that if there is a function that already does
that. I was thinking to "redim". But zero-ing an array is not redim's
main purpose. Is there a better way?

Thanks
Charles


--

Dave Peterson