Using VBA to find 0s and clear adjacent cells

rachel06

Board Regular
Joined
Feb 3, 2016
Messages
84
Office Version
  1. 365
Platform
  1. Windows
Hello,

I'm using the below code to delete entire rows of data that have a value of 0. Is there any way to alter this code to clear the contents of columns A-R if column B=0? Know that the headers on this data set start in row 9.

Sheets("Sheet1").Select
Worksheets("Sheet1").Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).Name = "Summary"

With Range("Summary")
.AutoFilter Field:=1, Criteria1:="0"
.Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
Worksheets("Summary").AutoFilterMode = False
End With

I'm sure this is something that's super easy, but I'm just not having luck. I'm not able to delete the rows in this instance because there are pivot tables to the right of the data.

TIA! :)
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Try this

VBA Code:
Sub test()
  Sheets("Sheet1").Select
  With Range("A9:R" & Range("B" & Rows.Count).End(xlUp).Row)
    .AutoFilter Field:=2, Criteria1:="0"
    .Offset(1).ClearContents
    ActiveSheet.AutoFilterMode = False
  End With
End Sub
 
Upvote 0
Solution
Brilliant! A9:R is the part I was getting wrong. Makes so much sense now.

Thanks so much!!
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,823
Messages
6,121,780
Members
449,049
Latest member
greyangel23

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