In my sheet 'Week' when I double click on a cell in column A, I expect the entire row…
- User
In my sheet 'Week' when I double click on a cell in column A, I expect the entire row from A to K to be copied and pasted directly beneath the row That I double clicked on. The VBA below creates the row, but only the value in column A is copied to the new row. When the new row is created, I want the values from A to K to be copied too. I also want a message to pop up that says, "Duplicate Row of Task has been created" line break "In original row, enter complete to close the row" line break "to archive progress of the task", vbInformation, "TASK PROGRESS"
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) Dim response As VbMsgBoxResult Dim lastRow As Long Dim rangeToCopy As Range Dim rangeToClear As Range
code' Check if double-click occurred in column A If Target.Column = 1 Then ' Prevent entering edit mode on double-click Cancel = True ' Check if the cell in column A below is empty If IsEmpty(Target.Offset(1, 0)) Then ' Ask user if they want to duplicate the task response = MsgBox("Do you want to duplicate the task?", vbQuestion + vbYesNo) If response = vbYes Then ' If empty, just copy the row directly Me.Unprotect Password:="edit" Application.EnableEvents = False Application.ScreenUpdating = False Target.Offset(1, 0).Value = Target.Value Application.EnableEvents = True Application.ScreenUpdating = True Me.Protect Password:="edit" Exit Sub Else Exit Sub End If End If ' Ask user if they want to duplicate the task response = MsgBox("Do you want to duplicate the task?", vbQuestion + vbYesNo) If response = vbYes Then Me.Unprotect Password:="edit" Application.EnableEvents = False Application.ScreenUpdating = False ' Get the last used row in column A lastRow = Cells(Rows.Count, 1).End(xlUp).Row ' Define the range to copy starting from the double-clicked cell Set rangeToCopy = Range(Target.Offset(1), Cells(lastRow, 11)) ' Copy the values one row down starting from the double-clicked cell rangeToCopy.Copy Destination:=Target.Offset(2) ' Define the range to clear just below the last row Set rangeToClear = Target.Offset(1).EntireRow ' Clear the values just below the last row rangeToClear.ClearContents ' Copy the value from the row above to the current row Target.Offset(1).Value = Target.Value Application.EnableEvents = True Application.ScreenUpdating = True Me.Protect Password:="edit" End If End If - Assistant
- User
The duplicate row was not created
- Assistant
- User
In the vBA code, I am expecting it to delete only the target row. It is deleting other rows and also creating rows: If Not Intersect(Target, targetSheet.Range("J2:J51")) Is Nothing Then targetSheet.Unprotect Password:="edit" For Each cell In targetSheet.Range("J2:J51") If cell.Value = "Completed" Then answer = MsgBox("Have you entered the Outcomes?", vbYesNo + vbQuestion) If answer = vbYes Then lastRow = archiveSheet.Cells(Rows.Count, 1).End(xlUp).Row + 1 targetSheet.Range("A" & cell.Row & ":K" & cell.Row).Copy archiveSheet.Range("A" & lastRow).PasteSpecial xlPasteValues clearRow = cell.Row targetSheet.Rows(clearRow).ClearContents pasteRow = clearRow lastRow = targetSheet.Cells(targetSheet.Rows.Count, "A").End(xlUp).Row Set copyRange = targetSheet.Range("A" & pasteRow + 1 & ":K" & lastRow).Offset(1, 0) copyRange.Copy Destination:=targetSheet.Range("A" & pasteRow) Else Application.Undo GoTo EndCode End If End If Next cell End If
- Assistant
- User
The now deletes the required row, but it also causes the row beneath to duplicate.
- Assistant
- User
It deleted only he contents of the row and left a blank row which I do not want. Why dont we archive the row then just delete the entire row.
- Assistant