Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. Sub DoLoop1_Sol() ' this is a Do While... loop
  2. Dim searchCol As Integer
  3. Dim nCols As Integer
  4. Dim rowCount As Integer
  5. Dim foundMatch As Boolean
  6. Dim searchName As String
  7. Dim isvalid As Boolean
  8.  
  9. Sheet1.Activate
  10.  
  11. nCols = Cells(1, Columns.Count).End(xlToLeft).Column
  12.  
  13. searchName = InputBox("Enter name of customer")
  14.  
  15. searchCol = InputBox("Enter year to search") - 2015
  16. Do While searchCol > nCols Or searchCol < 1
  17. searchCol = InputBox("Enter year to search again") - 2015
  18. Loop
  19.  
  20. rowCount = 2
  21. foundMatch = False
  22. Do While Cells(rowCount, searchCol).Value <> "" And foundMatch = False
  23. If LCase(Cells(rowCount, searchCol).Value) = LCase(searchName) Then
  24. foundMatch = True
  25. MsgBox searchName & " is found in record " & _
  26. rowCount - 1, vbInformation, "Found Match"
  27. Exit Do
  28. Else
  29. rowCount = rowCount + 1
  30. End If
  31. Loop
  32.  
  33. If Not foundMatch Then
  34. MsgBox "No match for " & searchName & " was found.", vbCritical, _
  35. "DoLoop1 - No Match"
  36. End If
  37.  
  38. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement