Assigning a value to an array cell

S

Srikanth Ganesan

Hi,

I am trying to assign a value to a specific cell in an array (inside a
For loop). But for some reason this assignment breaks the loop. Here's
the declaration and the For loop:

Dim yrow() As Integer
Dim i As Integer, k As Integer
k = 0
For i = 1 To lrow

If IsNumeric(Cells(i, 2).Value) = False Then
k = k + 1
MsgBox "*"
yrow(k) = i
MsgBox "**"
End If
i = i + 1
Next i
The First message box pops up but not the second. And the For loop is
not continued further (I guess it is broken)Please help.

Srikanth
 
T

Tom Ogilvy

Dim yrow() As Integer
Dim i As Integer, k As Integer
k = 0
' lrow gets assigned a value where?
Redim yrow(1 to lrow)
For i = 1 To lrow

If IsNumeric(Cells(i, 2).Value) = False Then
k = k + 1
MsgBox "*"
yrow(k) = i
MsgBox "**"
End If
i = i + 1
Next i

Redim Preserve yrow(1 to k)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top