Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub DoLoop1_Sol() ' this is a Do While... loop
- Dim searchCol As Integer
- Dim nCols As Integer
- Dim rowCount As Integer
- Dim foundMatch As Boolean
- Dim searchName As String
- Dim isvalid As Boolean
- Sheet1.Activate
- nCols = Cells(1, Columns.Count).End(xlToLeft).Column
- searchName = InputBox("Enter name of customer")
- searchCol = InputBox("Enter year to search") - 2015
- Do While searchCol > nCols Or searchCol < 1
- searchCol = InputBox("Enter year to search again") - 2015
- Loop
- rowCount = 2
- foundMatch = False
- Do While Cells(rowCount, searchCol).Value <> "" And foundMatch = False
- If LCase(Cells(rowCount, searchCol).Value) = LCase(searchName) Then
- foundMatch = True
- MsgBox searchName & " is found in record " & _
- rowCount - 1, vbInformation, "Found Match"
- Exit Do
- Else
- rowCount = rowCount + 1
- End If
- Loop
- If Not foundMatch Then
- MsgBox "No match for " & searchName & " was found.", vbCritical, _
- "DoLoop1 - No Match"
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement