View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Increment an Array question

You have to increment the Array.
It does increment the array first.

Explain where you think the existing code does not work. Maybe my
explanation was flawed.

Since this is part of a bigger routine, starting form scratch is probably
not an option.

--
Regards,
Tom Ogilvy




"Jim Cone" wrote in message
...
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