Delete Range based on Cell Value and Shift Up

JSAUS

New Member
Joined
Jun 11, 2020
Messages
7
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: 1

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,622
Office Version
  1. 2007
Platform
  1. Windows
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
 

JSAUS

New Member
Joined
Jun 11, 2020
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
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 :)
 

Watch MrExcel Video

Forum statistics

Threads
1,130,112
Messages
5,640,174
Members
417,130
Latest member
Darion2021

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
Top