I am getting an error on the line that starts If Not Intersect (Me ... of the following…
- User
I am getting an error on the line that starts If Not Intersect (Me ... of the following code, .... Private Sub Worksheet_Deactivate() 'calculate corresponding row in "PORDER" sheet based on the last active row in this sheet Dim lastRow As Long lastRow = Selection.Row
'check if the user is switching to the "PORDER" sheet If Not Intersect(Me.Next.Select, Me.Parent.Sheets("PREQUEST").UsedRange) Is Nothing Then 'locate corresponding row in "PORDER" sheet Dim sheetPORDERRow As Long sheetPORDERRow = Application.WorksheetFunction.Match(lastRow, Sheets("PORDER").Range("A:A"), 0) If Not IsError(sheetPORDERRow) Then 'found matching row in "PORDER" sheet Sheets("PORDER").Range("A" & sheetPORDERRow & ":M" & sheetPORDERRow).Calculate MsgBox "Corresponding row in ‘PORDER’ sheet: " & Sheets("PORDER").Range("A" & sheetPORDERRow).Address End If End If
'if the user is not switching to the "PORDER" sheet, do nothing End Sub
- Assistant
It is not clear what error message you are receiving on the line that starts with "If Not Intersect". However, one possible issue is that the code is designed to run within a specific worksheet (the worksheet where the code is placed). If this code is placed in a different worksheet, it may result in an error.
To fix this, you may need to modify the code by replacing instances of "Me" with the actual worksheet name where the code is placed. For example, instead of "Me.Next.Select", you can use "Worksheets("Sheet1").Next.Select" (replace "Sheet1" with the actual worksheet name).
Additionally, make sure that the worksheet name is spelled correctly and that it exists in the workbook, otherwise you'll get an error.
It's also a good practice to add error handling in the code to catch any errors that may occur during the execution of the code and handle them appropriately.