Clearing rows of data from a range (B:W) if column W has a specific value

d0rian

Active Member
Joined
May 30, 2015
Messages
313
Office Version
  1. 365
My data is in columns B:W (technically B2:W25000, since there's a header row)

For each row of data, Column W is either "d" or null ("").

Only rows where the value is "d" are relevant for me and I want to delete the contents of B:W in all the other rows.

I currently use a clunky method of sorting the range by col W, shuttling the non-"d" values to the bottom, then deleting the range where the null("") values start using a few helper cells. Would prefer some VBA that just cleared the rows I don't care about. (I don't care if it just leaves those rows blank; i.e. leaving a bunch of blank rows between the lines of relevant data).
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
How about
Code:
Sub DelW()
Range("W:W").AutoFilter 1, ""
Range("W2", Range("W" & Rows.Count).End(xlUp)).SpecialCells(xlVisible).EntireRow.Delete
End Sub
 
Upvote 0
Away from my file, will try when i get back, but looking at the code, realized that maybe i didn't stress that i only want to delete the contents from the data range (B2:W25000), NOT the entire row (because there are other unrelated formulas and tables to the right of column W)...i think that code will just wipe the entire row from (col A through col ZZZ or w/e)...?
 
Upvote 0
In that case try
Code:
Sub DelW()
Range("W:W").AutoFilter 1, ""
Range("B2", Range("W" & Rows.Count).End(xlUp)).SpecialCells(xlVisible).ClearContents
ActiveSheet.AutoFilterMode = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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