Reading first cell occurrence in a row and moving on to the next - VBS

93 views Asked by At

Let's say I have the following VBS code:

For Each cell in Sheet.UsedRange.Cells

 If IsNumeric(cell) Then
     i = i + 1 
     If i = 1 Then   ' get the first occurrence of the cell in a row
       ' finish code

I wish to get the first cell that's numeric in a row, ignore the remaining cells in the current row, and move on to the next row. I know it has to do with storing the value of the current row (cell.Row) but I can't figure out the condition.

Any help is greatly appreciated.

1

There are 1 answers

0
HelloNewWorld On
Sub findFristNumber()

Dim r As Integer, c As Integer
Dim cellValue

r = Sheet1.UsedRange.Rows.Count
c = Sheet1.UsedRange.Columns.Count

For i = 2 To r
    For j = 1 To c
        cellValue = Cells(i, j)
        If IsNumeric(cellValue) Then
            MsgBox cellValue
            Exit For
        End If
    Next j
Next i
End Sub