Sub Checks() Dim remindws As Worksheet Dim reminderCell As Range Dim lastRow As Long Dim…
- User
Sub Checks()
Dim remindws As Worksheet Dim reminderCell As Range Dim lastRow As Long Dim i As Long 'declare variable for loop counter Set remindws = Worksheets(Range("I2").Value) lastRow = remindws.Cells(remindws.Rows.count, "J").End(xlUp).Row 'find last row in column J For i = 1 To lastRow Set reminderCell = remindws.Cells(i, "J") If reminderCell.Value <> "" Then If reminderCell.Offset(0, -1).Value = "" Then Dim answer As VbMsgBoxResult Const ADMIN_REQUEST_EXISTS_MSG As String = "Tasks requiring Reminders Found. Check reminders listed to see if you want to continue with this New Reminder?" answer = MsgBox(ADMIN_REQUEST_EXISTS_MSG, vbYesNo + vbQuestion, "Continue or Not") If answer = vbYes Then Application.EnableEvents = False Call OutstandingReminder Exit Sub Else Call ClearReminder End If End If End If Next i
End Sub
This code does not find all the conditions where "J" <> "" and the Offset(0, -1).Value = ""
- Assistant
Based on the code provided, it seems like the conditions are not being met in the loop. Here are a few things you can check:
-
Double-check the data in column J. Make sure there are values that meet the condition - not empty.
-
Check the offset column. Make sure the column on the left of column J is empty for the relevant rows. If not, adjust the offset value accordingly.
-
If the offset column contains formulas, make sure they are not evaluating to an empty string ("") rather than a true empty cell.
-
Ensure that the range you are setting as remindws is correct. Double-check that the value in cell I2 corresponds to the correct worksheet.
-
Add a MsgBox statement to check the values of reminderCell and reminderCell.Offset(0, -1) for each iteration of the loop. This will help identify any issues with those values.
After reviewing these points, you should be able to identify why the code is not finding all the conditions where "J" <> "" and Offset(0, -1).Value = "".
-
- User
where in the code will I add the MsgBox
- Assistant
You can add the MsgBox statement right before the line
If reminderCell.Value <> "" Then. This will allow you to check the values ofreminderCellandreminderCell.Offset(0, -1)for each iteration of the loop:For i = 1 To lastRow Set reminderCell = remindws.Cells(i, "J") MsgBox "Reminder Cell Value: " & reminderCell.Value _ & vbCrLf & "Offset Cell Value: " & reminderCell.Offset(0, -1).Value If reminderCell.Value <> "" Then ' Rest of your code... End If Next iThe MsgBox will display the values of
reminderCellandreminderCell.Offset(0, -1)for each iteration. This will help you determine if the values are as expected and assist in troubleshooting any issues that may arise.