Set adminRequestCell = wscf.Range("B:B").Find("Admin Request", , xlValues, xlWhole,…
- User
Set adminRequestCell = wscf.Range("B:B").Find("Admin Request", , xlValues, xlWhole, xlByColumns)
In the code below does not appear to be working. The Value 'Admin Request' exists in the soucre but I do not get any prompts. Can you identify the error and any other errors.
Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Not Intersect(Target, Range("B2:E2")) Is Nothing Then Exit Sub 'Currently within B2:F2
If Not Intersect(Target, Range("F2")) Is Nothing Then 'Currently in F2 GoTo COMPLETE
If Not Intersect(Target, Range("A2")) Is Nothing Then 'Currently in A2 Application.Calculate Application.Wait (Now + TimeValue("0:00:02"))
Dim wscf As Worksheet Dim adminRequestCell As Range Dim isAdminRequestPresent As Boolean Const ADMIN_REQUEST_EXISTS_MSG As String = "Admin Request has already been sent. Do you want to RE-SEND?" Set wscf = Worksheets(Range("I2").Value) Set adminRequestCell = wscf.Range("B:B").Find("Admin Request", , xlValues, xlWhole, xlByColumns) If Not adminRequestCell Is Nothing Then 'Admin Request Found answer = MsgBox(ADMIN_REQUEST_EXISTS_MSG, vbYesNo + vbQuestion, "Resend details") If answer = vbNo Then GoTo COMPLETE End If End If
If adminRequestCell Is Nothing Then 'Admin Request NOT Found GoTo CHECKS End If
- Assistant
The code appears to be incomplete as there is no ending statement for the initial If statement (between lines 6 and 8). Additionally, there is no label for the CHECKS section that is referenced when adminRequestCell is not found. Here is a corrected version of the code:
Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Not Intersect(Target, Range("B2:E2")) Is Nothing Then Exit Sub 'Currently within B2:F2
If Not Intersect(Target, Range("F2")) Is Nothing Then 'Currently in F2 GoTo COMPLETE End If
If Not Intersect(Target, Range("A2")) Is Nothing Then 'Currently in A2 Application.Calculate Application.Wait (Now + TimeValue("0:00:02"))
Dim wscf As Worksheet Dim adminRequestCell As Range Dim isAdminRequestPresent As Boolean Const ADMIN_REQUEST_EXISTS_MSG As String = "Admin Request has already been sent. Do you want to RE-SEND?" Set wscf = Worksheets(Range("I2").Value) Set adminRequestCell = wscf.Range("B:B").Find("Admin Request", , xlValues, xlWhole, xlByColumns) If Not adminRequestCell Is Nothing Then 'Admin Request Found answer = MsgBox(ADMIN_REQUEST_EXISTS_MSG, vbYesNo + vbQuestion, "Resend details") If answer = vbNo Then GoTo COMPLETE End If ElseIf adminRequestCell Is Nothing Then 'Admin Request NOT Found GoTo CHECKS End If
- User
i added your correction but it still not working
- Assistant
There could be several issues that are causing the code to not work as intended. Here are some troubleshooting steps you can try:
-
Check the worksheet name in cell I2: Double-check that the worksheet name in cell I2 is correct and exists. If it is not valid, the code will not function as intended.
-
Check the range in which the code is triggered: Make sure that the Worksheet_Change event is triggered when data is entered in the correct range (B2:F2). If data is entered elsewhere on the worksheet, the code will not execute.
-
Debug the code: Add some Debug.Print statements to the code to help identify which lines are executing and when. For example, you could add the following statement after line 14:
Debug.Print "adminRequestCell address: " & adminRequestCell.Address -
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.