I wrote a vba code to check if column B has the word Reminder at the start value.…
- User
I wrote a vba code to check if column B has the word Reminder at the start value. Unfortunately it is not working. Can you help? Sub Checks()
Dim wscf As Worksheet Dim isReminderPresent As Boolean Dim insured As Boolean Dim dbsd As Boolean Dim lastRow As Long Dim wsjr As Worksheet Dim wswp As Worksheet Dim adminReminderCell As Range Dim answer As VbMsgBoxResult
Set wscf = Worksheets(Range("I2").Value) Set wsjr = Worksheets("Reminders")
Set adminReminderCell = Nothing
If Not wscf Is Nothing Then Set adminReminderCell = wscf.UsedRange.Columns("B").Find("Reminder * ", , xlValues, xlWhole, xlByColumns) End If
If Not adminReminderCell Is Nothing Then 'Reminder Found 'Range("B2").Select Call OutstandingReminder
Const ADMIN_REQUEST_EXISTS_MSG As String = "Reminder Found. Do you want to create a New Reminder?" If Not adminReminderCell Is Nothing Then 'Reminder Found in Contractors File answer = MsgBox(ADMIN_REQUEST_EXISTS_MSG, vbYesNo + vbQuestion, "Resend details")
If answer = vbYes Then
Call EnterCheckReminder
Else
Call ClearReminder
Exit Sub
End If End If End If
End Sub
- Assistant
It looks like the problem may be with the line:
Set adminReminderCell = wscf.UsedRange.Columns("B").Find("Reminder * ", , xlValues, xlWhole, xlByColumns)
In the Find function, you have "Reminder * " as the search term, but the asterisk character (*) may not be recognized as a wildcard character in this context.
Instead, try using:
Set adminReminderCell = wscf.Range("B:B").Find("Reminder", , xlValues, xlWhole, xlByColumns)
This should search for any cells in column B that contain the exact word "Reminder" at the beginning of the cell value.
- User
It is still not finding the word Reminder
- Assistant
If the previous solution did not work, here are some additional troubleshooting steps:
-
Check the worksheet that you are trying to search in (referenced by wscf) and ensure that it actually contains data in column B that starts with the word "Reminder." If there is no data that matches the search criteria, the function will return "Nothing."
-
Try adding a message box to display the value of adminReminderCell after it is assigned. This can help you determine if the variable is actually being set to a range object:
If Not adminReminderCell Is Nothing Then 'Reminder Found MsgBox "Reminder found at cell " & adminReminderCell.Address Call OutstandingReminder ' Rest of code omitted for brevity End If-
Check that the worksheet name in Range("I2").Value actually corresponds to the worksheet that you are trying to search. If this value is incorrect, then your code will be searching the wrong worksheet, leading to incorrect results.
-