How to create a Macro to delete rows in multiple sheets

tctran

New Member
Joined
Sep 12, 2014
Messages
7
Hello,

I have a spreadsheet with multiple sheets and would like to create a macro to delete the entire row(s) of each worksheet that contain a "0" value. I have a Y/N Flag column on all worksheets and want to create a macro to delete the entire row(s) on the Y/N Flag column on all sheets that has a value of "0" on the cell. Is it possible to create a macro to do this task in Excel? I've done some searches but not finding any thread similiar to this. Any help you can provide would be greatly appreciated.

Thank you,
TC
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
check whether this macro gets you what you want. if necessary modify the macro and check
check this macro in exptl data and not original data.

Code:
Option Compare Text
Sub tst()
Dim j As Long, yncol As Long, r As Range, filt As Range
For j = 1 To Worksheets.Count
With Worksheets(j)
yncol = .Rows("1:1").Cells.Find(what:="Y/N", lookat:=xlWhole).Column
Set r = .Range("A1").CurrentRegion
r.AutoFilter field:=yncol, Criteria1:="No"
r.Offset(1, 0).Resize(r.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
.AutoFilterMode = False
End With
Next j
End Sub
 
Upvote 0
check whether this macro gets you what you want. if necessary modify the macro and check
check this macro in exptl data and not original data.

Code:
Option Compare Text
Sub tst()
Dim j As Long, yncol As Long, r As Range, filt As Range
For j = 1 To Worksheets.Count
With Worksheets(j)
yncol = .Rows("1:1").Cells.Find(what:="Y/N", lookat:=xlWhole).Column
Set r = .Range("A1").CurrentRegion
r.AutoFilter field:=yncol, Criteria1:="No"
r.Offset(1, 0).Resize(r.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
.AutoFilterMode = False
End With
Next j
End Sub

Thank you very much for your help! I will give it a try.
 
Upvote 0

Forum statistics

Threads
1,203,061
Messages
6,053,307
Members
444,651
Latest member
markkuznetsov1

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