Hi guys im trying to create a searchable user form but have come unstuck.
When I enter the search details in txtAmount - my search box; hit the find btn, I get a runtime error 9 Subscript out of range.
This is my code any help would be cool.
Private Sub cmdFind_Click()
Dim totRows As Long, i As Long
totRows = Worksheets("Sheet2").Range("C1").CurrentRegion.Rows.Count
If txtAmount = "" Then
MsgBox "Enter Search Amount"
End If
For i = 2 To totRows
If Trim(Sheet2.Cells(i, 3)) <> Trim(txtAmount.Text) And i = totRows Then
MsgBox "Not Found"
End If
If Trim(Sheet2.Cells(i, 3)) = Trim(txtAmount.Text) Then
txtcmr.Text = Sheet2.Cells(i, 2)
txtAccNo.Text = Sheet2.Cells(i, 9)
Exit For
End If
Next i
End Sub
When I enter the search details in txtAmount - my search box; hit the find btn, I get a runtime error 9 Subscript out of range.
This is my code any help would be cool.
Private Sub cmdFind_Click()
Dim totRows As Long, i As Long
totRows = Worksheets("Sheet2").Range("C1").CurrentRegion.Rows.Count
If txtAmount = "" Then
MsgBox "Enter Search Amount"
End If
For i = 2 To totRows
If Trim(Sheet2.Cells(i, 3)) <> Trim(txtAmount.Text) And i = totRows Then
MsgBox "Not Found"
End If
If Trim(Sheet2.Cells(i, 3)) = Trim(txtAmount.Text) Then
txtcmr.Text = Sheet2.Cells(i, 2)
txtAccNo.Text = Sheet2.Cells(i, 9)
Exit For
End If
Next i
End Sub