Set rng_dest = Sheets("Database1").Range("B:K") Do Until Sheets("Database1").Range("A" & i).Value = "" If Sheets("Database1").Range("A" & i ).Value = Sheets("Report1").Range("Q5").Value Then Sheets("Database1").Range("A" & i).Entire row.Delete i = 1 End If i = i + 1 Loop
Store Column I before clearing the row and then write it back.
Option Explicit
Sub ClearRows()
Dim v, tmp
Dim i As Long, lastrow As Long, n As Long
v = Sheets("Report1").Range("Q5").Value
With Sheets("Database1")
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 1 To lastrow
If .Cells(i, "A") = v Then
tmp = .Cells(i, "I")
.Rows(i).ClearContents
.Cells(i, "I") = tmp
n = n + 1
End If
Next
End With
MsgBox n & " rows cleared that matched '" & v & "'", vbInformation
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.