When I double click in column G of my worksheet 'Week' I get an error 'Object Required'…
- User
When I double click in column G of my worksheet 'Week' I get an error 'Object Required' om the line 'If Target.Column <> 9 Then' When the error appears, the worksheet 'Planner' is activated for reasons unknown. Can you please correct the error and make the code more efficient, In the module:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) Dim response As VbMsgBoxResult Dim originalSheet As Worksheet Set originalSheet = ThisWorkbook.Sheets("Week") ThisWorkbook.Sheets("Week").Unprotect Password:="edit" Application.EnableEvents = False Application.ScreenUpdating = False
' Check if double-click occurred in column A If Target.Column <> 1 Then GoTo ColumnG End If If Not Intersect(Target, Me.Range("A2:A" & Me.Rows.count)) Is Nothing Then ' Prevent entering edit mode on double-click Cancel = True ' Ask user if they want to duplicate the task response = MsgBox("Do you want to duplicate the task?", vbQuestion + vbYesNo) If response = vbYes Then Dim originalRow As Range Dim cellA As Range Dim wsArchive As Worksheet Dim nextRow As Long Set wsArchive = ThisWorkbook.Sheets("Archive") Set originalRow = Range(Target, Target.Offset(, 10)) wsArchive.Unprotect Password:="edit" ' Find the next available row in the Archive sheet nextRow = wsArchive.Cells(wsArchive.Rows.count, 1).End(xlUp).row + 1 ' Copy the original row to the next available row in the Archive sheet originalRow.Copy wsArchive.Range("A" & nextRow).PasteSpecial xlPasteValues wsArchive.Cells(nextRow, 13).Value = "Week" wsArchive.Protect Password:="edit" ' Insert a new row below the double-clicked cell Target.Offset(1).EntireRow.Insert Shift:=xlDown ' Archive the original values originalRow.Copy wsArchive.Range("A" & nextRow + 1).PasteSpecial xlPasteValues wsArchive.Cells(nextRow + 1, 13).Value = "Week" ' Ask user if they want to replace Execution Notes with Outcomes response = MsgBox("Do you also wish to replace your Execution Notes with Outcomes?", vbQuestion + vbYesNo) If response = vbYes Then ' Replace Execution Notes with Outcomes Target.Offset(0, 8).Value = Target.Offset(0, 10).Value ' Make additional modifications to the new row Target.Offset(1, 8).Value = "ARCHIVED. Enter 'Cancelled' to delete" Target.Offset(0, 10).Value = "ADJUST. Execution & Status" ' Display the message MsgBox "Duplicate Row of Task has been created" & vbCrLf & _ "In original row, enter complete to close the row" & vbCrLf & _ "to archive progress of the task", vbInformation, "TASK PROGRESS" ' Switch back to the original sheet originalSheet.Activate End If End If End IfColumnG: ' Check if the double-click is in column G (2 to n) If Target.Column <> 7 Then GoTo ColumnI End If If Not Intersect(Target, Me.Range("G2:G" & Me.Rows.count)) Is Nothing Then If IsDate(Target.Value) Then ' Call the second module and pass the target address Call WriteToNotepad(Target.Address) Cancel = True ' Prevent the default double-click action (edit mode) End If End If
- Assistant