View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz JLGWhiz is offline
external usenet poster
 
Posts: 3,986
Default How come VBA if clause fails?

But why didn't my
version work? Just curious


For i = 0 To maxr
If sRange.Cells(row, col).Value < "" Then
' This if() NEVER passes - ???????????????????????
buffer(size) = sRange.Cells(row, col).Value
size = size + 1
End If
col = col + 1
Next i



"Zilla" wrote:

The For ... Next loop is useless because you do not use the variable i in
the intervening code to do anything. You would need to use it like
Cells(row, i) or
Cells(i, col) depending on which way you want to move.

When you used sRange.Cells(row, col), you essentially create a circular
reference. Cells(row, col) by definition are part of sRange. Remember row =
sRange.Row?
You should not have used sRange as part of the cell designation but just use
the
If Cells(i, col) = etc. Top down Parent/Child would be
Workbook.Sheet.Range or Cell. The cell is a range, so if you use Cells(row,
col) don't use a Range variable and vice versa.

It takes a while to pull all this stuff together, but you're getting there.