View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Zilla[_4_] Zilla[_4_] is offline
external usenet poster
 
Posts: 17
Default How come VBA if clause fails?

On Jan 17, 6:14*pm, Zilla wrote:
On Jan 17, 5:26*pm, Per Jessen wrote:





On 17 Jan., 23:10, Zilla wrote:


I have the following subroutine. Why can't I see the passed-in Range's
Cells(x,y).Value?


Sub getDataInfo2(sRange As Range)
* * Const maxr = 15
* * Const defSize = 100
* * Dim row As Integer
* * Dim col As Integer
* * Dim i As Integer
* * Dim size As Integer
* * Dim buffer(defSize)


* * ' Get data from source range
* * row = sRange.row
* * col = sRange.Column
* * size = 0
* * 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
End Sub


Sub test()
* * Dim baseBook As Workbook
* * Dim currSheet As Worksheet
* * Dim sRange as Range


* *set baseBook = ThisWorkbook
* *set currSheet = baseBook.Sheets(2)
* *currSheet.Activate
* *set sRange = currSheet.Range("A1:J1")
* *' I CAN SEE CELL VALUES IN THE RANGE HERE
* *Call getDataInfo2(sRange)
End Sub


Any clues?


Hi


Try this


Sub getDataInfo2(sRange As Range)
* * Const defSize = 100
* * Dim size As Integer
* * Dim buffer(defSize)


* * ' Get data from source range


* * size = 0
* * For Each c In sRange
* * * * If c.Value < "" Then
* * * * * * buffer(size) = c.Value
* * * * * * size = size + 1
* * * * End If
* * Next
End Sub


//Per- Hide quoted text -


- Show quoted text -


Thanks again Jason. I'll try your code tomorrow. But why didn't my
version work? Just curious...- Hide quoted text -

- Show quoted text -


Sorry, I meant Pe "Jessen" :)