如何修改VBA删除行代码为替换XXX值以保留序列号序列?
Solution to Mark Selected Row with "XXX" Instead of Deleting
To preserve your serial number sequence, replace the row deletion logic with code that overwrites the row's data cells with "XXX". Here's the modified full code:
Private Sub ButtonDelete_Click() If selected_List = 0 Then MsgBox "No Delegation is selected.", vbOKOnly + vbInformation, "Delete" Exit Sub End If Dim i As VbMsgBoxResult i = MsgBox("Do you want to mark the selected Delegation as XXX?", vbYesNo + vbQuestion, "Confirmation") If i = vbNo Then Exit Sub Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("NEWROUND") Dim targetRow As Long targetRow = selected_List + 1 ' Replace all cells from column B to the last used column in the row with "XXX" ws.Range(ws.Cells(targetRow, 2), ws.Cells(targetRow, ws.Cells(targetRow, ws.Columns.Count).End(xlToLeft).Column)).Value = "XXX" Call RESET MsgBox "Selected Delegation has been marked as XXX.", vbOKOnly + vbInformation, "Marked" End Sub
Key Changes:
- Removed the row deletion line and replaced it with flexible code to overwrite relevant cells with
XXX(assumes your serial number is in column A; adjust the starting column number if needed). - Updated the confirmation prompt to match the new action of marking instead of deleting.
- Adjusted the final message box text to reflect the completed action accurately.
Customization Notes:
- If your serial number is in a column other than A, change the
2inws.Cells(targetRow, 2)to the corresponding column number (e.g., 3 for column C). - To overwrite the entire row including the serial number, use
ws.Rows(targetRow).Value = "XXX"instead of the range-specific line.
内容的提问来源于stack exchange,提问作者Funny Memo Ms
相关产品推荐
相关产品推荐

