View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Per Jessen Per Jessen is offline
external usenet poster
 
Posts: 1,533
Default Range, select, and printing arrays

Hi Jeff

Thanks for your reply.


ReDim p(1)

Why do you only ReDim the array if the user wants to see the primes? Does
the (1) just tell the compiler that it's 1 dimensional?


The ReDim statement is needed to declare the size of the array before you
can assign any value to it, ie not needed if the user don't want to see the
primes. See the array as a worksheet with 1 row and one column. As the code
ReDim later on the array will have 2 rows and 1 column and so on..


If Cell.Value = "Prime" Then

How do you tell VBA not to be case specific?


If LCase(Cell.Value) = "prime" Then



ReDim Preserve p(UBound(p) + 1)

I'm still not too sure on this. It looks like you are dimensioning the
array and keeping the values currently in the array. Why do you need the
+1? If the index goes from 1 to UBound (since we set this option), wont
UBound(p) do the trick?


UBound(p) is the current size of the last dimension in the array, so +1 is
needed to expand the array.

Preserve is as you think used to keep the values currently in the array.


For c = 1 To UBound(p) - 1

Don't we lose the last value in the array with the - 1 ?


No because the array is expaded after the last number is assigned to the
array. If you remove the -1 you will have a zero value as last item.

Hopes this was explaination enough.

Best regards,
Per