Delete Row if criteria is met

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,404
Office Version
  1. 2016
Platform
  1. Windows
Guys - I'm using this to copy values to another workbook only if the cell in column A and D are not blank;

Code:
For Each Cell In Sheet1.Range("A2:A95")If Cell.Value <> "" Then
If Cell.Offset(0, 3).Value <> "" Then[INDENT]Set ws = DestFile.Sheets("Data")[/INDENT]
[INDENT]iRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row[/INDENT]
[INDENT=2]ws.Cells(iRow, 3).Value = Cell.Value
ws.Cells(iRow, 1).Value = Cell.Offset(0, 2).Value
ws.Cells(iRow, 2).Value = Cell.Offset(0, 3).Value[/INDENT]
[INDENT]End If[/INDENT]
End If
Next

Once that data has been copied, I would like the row containing that data to be deleted, (shift up). Can someone show me how please?
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi,
untested but see if this update to your code does what you want


Code:
    Dim DeleteRow As Range
    Set ws = DestFile.Sheets("Data")
    For Each cell In Sheet1.Range("A2:A95")
        iRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Offset(1, 0).Row
        With cell
            If Len(.Value) > 0 And Len(.Offset(0, 3).Value) > 0 Then
                ws.Cells(iRow, 1).Resize(, 3).Value = Array(.Offset(0, 2).Value, .Offset(0, 3).Value, .Value)
                If DeleteRow Is Nothing Then Set DeleteRow = cell Else Set DeleteRow = Union(DeleteRow, cell)
            End If
        End With
    Next cell
    If Not DeleteRow Is Nothing Then DeleteRow.EntireRow.Delete shift:=xlShiftUp

Dave
 
Upvote 0

Forum statistics

Threads
1,215,347
Messages
6,124,421
Members
449,157
Latest member
mytux

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top