Skip to content
🤔prompts chat🧠
🔍
question:In my sheet, I enter data into rows from row 2 downwards. I want a vba code that will do the following. When I enter the value 'completed' into column J, then the entire row from column A to K where I entered completed is copied to the next available row in sheet Archive and then the row is deleted.

answer:Certainly! You can use the following VBA code to achieve your requirement: ``` Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Range("J:J")) Is Nothing Then ' Check if change occurred in column J Dim cell As Range For Each cell In Intersect(Target, Range("J:J")) ' Loop through changed cells in column J If UCase(cell.Value) = "COMPLETED" Then ' Check if value is "completed" (case-insensitive) Dim lastRow As Long lastRow = Sheets("Archive").Cells(Rows.Count, 1).End(xlUp).Row + 1 ' Find next available row in "Archive" sheet Me.Range("A" & cell.Row & ":K" & cell.Row).Copy Destination:=Sheets("Archive").Range("A" & lastRow) ' Copy row to "Archive" sheet Me.Rows(cell.Row).Delete ' Delete the row in current sheet Exit For ' Exit loop after processing one "completed" entry End If Next cell End If End Sub ``` To use this code, follow these steps: 1. Right-click on the sheet name where you want this functionality and select "View Code." 2. Paste the above code into the code window that appears. 3. Save the workbook as a macro-enabled workbook (.xlsm) if it's not already saved that way. From now on, whenever you enter the value "completed" in column J of that sheet, the entire row from column A to K where you entered "completed" will be copied to the next available row in the "Archive" sheet, and the row will be deleted from the current sheet.

question:is it possible to copy the values only without any formatting

answer:Yes, it is possible to copy only the values without any formatting. You can modify the code as shown below: ```vba Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Range("J:J")) Is Nothing Then ' Check if change occurred in column J Dim cell As Range For Each cell In Intersect(Target, Range("J:J")) ' Loop through changed cells in column J If UCase(cell.Value) = "COMPLETED" Then ' Check if value is "completed" (case-insensitive) Dim lastRow As Long lastRow = Sheets("Archive").Cells(Rows.Count, 1).End(xlUp).Row + 1 ' Find next available row in "Archive" sheet Me.Range("A" & cell.Row & ":K" & cell.Row).Copy Sheets("Archive").Range("A" & lastRow).PasteSpecial xlPasteValues ' Paste values only in "Archive" sheet Application.CutCopyMode = False ' Clear clipboard Me.Rows(cell.Row).Delete ' Delete the row in current sheet Exit For ' Exit loop after processing one "completed" entry End If Next cell End If End Sub ``` This modified code uses the `PasteSpecial xlPasteValues` method to paste only the values without any formatting. It clears the clipboard after pasting and before deleting the row in the current sheet. Note: Ensure that the "Archive" sheet exists in your workbook with the desired range to receive the copied values.

question:I have a sheet named planner that has links to all my other sheet in the workbook. If I delete a row in a sheet the cell address in sheet Planner loses the cell address. how can I prevent this

answer:To prevent the cell references in the "Planner" sheet from losing their connection when a row is deleted in another sheet, you can use the `HYPERLINK` function along with the `INDIRECT` function in the "Planner" sheet. Assuming that the cell references in the "Planner" sheet are stored in column A, you can modify the formulas in that column to use the `HYPERLINK` function. Here's an example: ```vba =HYPERLINK("#'" & INDIRECT("SheetName") & "'!A1", "Link Text") ``` Replace "SheetName" with the actual sheet name from which you want to create the link. The `INDIRECT` function retrieves the value in the cell which contains the sheet name. The `HYPERLINK` function then creates a clickable link with the specified link text. By using this approach, even if a row is deleted in the referenced sheet, the cell references in the "Planner" sheet will still maintain their connection. Make sure to update the formulas accordingly for each cell reference in column A of the "Planner" sheet. Note: The above formula assumes that all the referenced sheets have data starting from cell A1. Modify the formula accordingly if the referenced data starts from a different cell address.

question:The links in my sheet Planner are just simple links like this '=Day!A2'. I want to maintain this link even if the row in sheet Day is deleted

answer:I apologize for

Released under the MIT License.

has loaded