Delete Range based on Cell Value and Shift Up

JSAUS

New Member
Joined
Jun 11, 2020
Messages
14
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I know this has been asked before, but I can't get any of the examples to work for my data.
I have data in columns A:D.
I need to check column D and if cell is 0 (a result of a formula) then delete A:D of that row and shift up.
Then go to next.
I only want to delete columns A to D because there is data in other columns that needs to stay there.

TIA
 

Attachments

  • Range.png
    Range.png
    23.3 KB · Views: 3

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try this

VBA Code:
Sub DeleteAD()
  Dim lr As Long, i As Long, r As Range
  lr = Range("D" & Rows.Count).End(3).Row
  Set r = Range("A" & lr + 1 & ":D" & lr + 1)
  For i = 1 To lr
    If Range("D" & i).Value = 0 Then Set r = Union(r, Range("A" & i & ":D" & i))
  Next
  r.Delete xlUp
End Sub
 
Upvote 0
Thank you! That works perfectly.
I can understand most of that code, except the ".End(3)". Can you please explain to me what that does? Is that the same as "End(xlUp).Row"?

Thanks :)
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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