Thread: Adding to Array
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Auric__ Auric__ is offline
external usenet poster
 
Posts: 538
Default Adding to Array

joeu2004 wrote:

"Jim Cone" wrote:
"Charlotte E."
I have an array, which starts out like this:
PWL = Array("Data1", "Data2", "Data3")
Now I would like to add a value to this array?
As if it had started out like this:
PWL = Array("Data1", "Data2", "Data3", "Data4")


Dim PWL As Variant
PWL = Array("Data1", "Data2", "Data3")
ReDim Preserve PWL(0 To 3)
PWL(3) = "Data4"


But if Option Base 1 were set, we would need ReDim Preserve PWL(1 to 4).

More generally:

ReDim Preserve PWL(LBound(PWL) to UBound(PWL)+1)


No need to specify the lower bound in this case:
ReDim Preserve PWL(UBound(PWL)+1)

--
Error -53. We'd tell you what that means, but we don't know either.