View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Increment an Array question

SG,

You have to increment the Array.
I started from scratch and wrote something I think
is close to what you want? See if this is any help...
'-------------------------------------------------------

Sub AnotherTest()
Dim i As Long
Dim N As Long
Dim X As Long
Dim SearchRange As Excel.Range
Dim varr() As Double

Set SearchRange = Range(Cells(10, 1), Cells(Rows.Count, 1).End(xlUp))
N = SearchRange.Count
ReDim varr(1 To N)

For i = N To 1 Step -1
If SearchRange(i).Value = "Now Cough" Then
X = X + 1
varr(X) = SearchRange(i).Offset(0, 1).Value
End If
Next 'i
ReDim Preserve varr(1 To X)

'Just an example - as could run out of columns
Range(Cells(5, 4), Cells(5, 3 + X)).Value = varr()

Set SearchRange = Nothing
End Sub
'------------------------------------------------------------

Regards,
Jim Cone
San Francisco, USA


"S G Booth" wrote in message
...
I'm searching up a column looking for a particular value.
When found, I need to add a range offset from that cell
to an array.
I find that the following code is overwriting varr(1) each
time....so the array never builds correctly
i = i + 1
If IsEmpty(varr(1)) Then
Set varr(1) = .Range("B" & StartRw)
Else
ReDim Preserve varr(1 To UBound(varr) + 1)
Set varr(UBound(varr)) = .Range("B" & StartRw)
End If

Why is the array not building correctly, please?

Regards