I took a slightly different approach to your problem. In cases like yours, I usually use a 'Shadow Sheet' containing a copy of the original data and do all the testing on the 'Shadow' Sheet. When testing is complete, I delete the Shadow Sheet and use the Original Sheet in production. See the code that follows which is included in the Sample Workbook. All activity takes place on Sheet 'Test Bed'.
Option Explicit
Const sTestSheetNAME = "Test Bed"
Const sOriginalDataSheetNAME = "Sheet1"
Const nFirstDataROW = 5
Sub ClearOneRowAtATime()
'This clears all data from the first row (starting at row 5) that contains data
Dim myWorkbook As Workbook
Dim myWorksheet As Worksheet
Dim iCount As Long
Dim iLastRowUsed As Long
Dim iRow As Long
'Create the Worksheet Objects
Set myWorkbook = ThisWorkbook
Set myWorksheet = myWorkbook.Sheets(sTestSheetNAME)
'Find the Last Row Used (NOTE: A runtime error will occur if the entire sheet has no data)
iLastRowUsed = myWorksheet.Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
'Find the First Row with Data (counts Numbers only)
'Clear Data From that Row
For iRow = nFirstDataROW To iLastRowUsed
iCount = Application.WorksheetFunction.Count(myWorksheet.Rows(iRow))
'Debug.Print iRow, iCount 'Output to the Immediate Window (Ctrl G in the Debugger)
'If the Row contains Numbers, clear all data from the Row and Exit the loop
If iCount > 0 Then
myWorksheet.Rows(iRow).ClearContents
Exit For
End If
Next iRow
'Clear Object Points
Set myWorkbook = Nothing
Set myWorksheet = Nothing
End Sub
Sub RestoreOneRowAtATime()
'This restores data from the first row (starting at from the rear) that contains no data
Dim myWorkbook As Workbook
Dim mySourceWorksheet As Worksheet
Dim myDestinationWorksheet As Worksheet
Dim r As Range
Dim iCount As Long
Dim iLastRowUsed As Long
Dim iRow As Long
'Create the Worksheet Objects
Set myWorkbook = ThisWorkbook
Set mySourceWorksheet = myWorkbook.Sheets(sOriginalDataSheetNAME)
Set myDestinationWorksheet = myWorkbook.Sheets(sTestSheetNAME)
'Find the Last Row Used (NOTE: A runtime error will occur if the entire sheet has no data)
iLastRowUsed = myDestinationWorksheet.Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
'Find the First Row with Data (counts Numbers only)
'Copy Data From the Source Worksheet Row to the Destination Worksheet Row, then Exit the Loop
For iRow = nFirstDataROW To iLastRowUsed
iCount = Application.WorksheetFunction.Count(myDestinationWorksheet.Rows(iRow))
'Debug.Print iRow, iCount 'Output to the Immediate Window (Ctrl G in the Debugger)
'If the Row contains Numbers, Copy the 'Previous Row' Numbers to the Destination Worksheet, then Exit the loop
If iCount > 0 Then
myDestinationWorksheet.Rows(iRow - 1).Value = mySourceWorksheet.Rows(iRow - 1).Value
Exit For
End If
Next iRow
'Clear Object Points
Set myWorkbook = Nothing
Set mySourceWorksheet = Nothing
Set myDestinationWorksheet = Nothing
End Sub
Sub RestoreAllData()
'This restores all Data from the 'Original' Sheet to the 'Test Bed' Sheet
Dim myWorkbook As Workbook
Dim mySourceWorksheet As Worksheet
Dim myDestinationWorksheet As Worksheet
Dim r As Range
'Create the Worksheet Objects
Set myWorkbook = ThisWorkbook
Set mySourceWorksheet = myWorkbook.Sheets(sOriginalDataSheetNAME)
Set myDestinationWorksheet = myWorkbook.Sheets(sTestSheetNAME)
'Copy All Data From Source WorkSheet to the Destination Worksheet
For Each r In mySourceWorksheet.UsedRange
myDestinationWorksheet.Range(r.Address).Value = r.Value
Next r
'Clear Object Points
Set myWorkbook = Nothing
Set mySourceWorksheet = Nothing
Set myDestinationWorksheet = Nothing
End Sub
Lewis
Bookmarks