Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redimming and Array in VBA 2

Status
Not open for further replies.

bikerboy718

Programmer
Feb 11, 2005
195
US
I am not sure if this is possible in VBA but can i Redim and array using the preserve keyword.

This is what i have so far.

Range("A1").Select
Selection.End(xlDown).Select
RowCount = ActiveCell.Row
Dim arrlen As Integer
arrlen = 0

Dim acctNumArr(0) As String

For i = 1 To RowCount
Range("H" & i).Select
rowH = ActiveCell.Value
For j = 0 To arrlen
If acctNumArr(j) = ActiveCell.Value Then
flag = True
Else
flag = False
End If
Next

If flag = False Then
arrlen = arrlen + 1
ReDim Preserve acctNumArr(arrlen)
acctNumArr(arrlen) = ActiveCell.Value
End If
Next


The problem that i run into is that i continue to get a Array alredy dimensioned error. Any help is greatly appreciated.

 
Dim acctNumArr(0) As String

That line dimensions the array wih only 1 element (the zero'ith). To dimension a dynamic array...

Dim acctNumArr() As String

You can only redim a dynamic array.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Hi,
Code:
    Dim arrlen As Integer
    Dim acctNumArr() As String
    
    RowCount = Range(Range("A1"), Range("A1").End(xlDown)).Rows.Count
    arrlen = 0
    
    flag = False
    
    For i = 1 To RowCount
        ReDim Preserve acctNumArr(arrlen)
        acctNumArr(arrlen) = Cells(i, "H").Value
        arrlen = arrlen + 1
        
    Next

Skip,

[glasses] [red]Be advised:[/red] When you ignite a firecracker in a bowl of vanilla, chocolate & strawberry ice cream, you get...
Neopolitan Blownapart! [tongue]


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top