Delete Row If Cell Contains Value In Entire Workbook

califorlina

New Member
Joined
Mar 3, 2015
Messages
16
Hi, Completely stuck on this - I would like this macro to search all worksheets in the workbook and delete any row that contains 920 in column B. The code below only deletes on the active sheet:

Sub DeleteRowsTest()

Dim i As Integer
Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
For i = 1 To Range("B" & "65536").End(xlUp).Row Step 1
If Application.WorksheetFunction.CountIf(Range("A" & i & ":AZ" & i), "920") > 0 Then
ws.Range("B" & i).EntireRow.Delete
End If
Next i
Next ws

End Sub

Any assistance would be greatly appreciated!
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

califorlina

New Member
Joined
Mar 3, 2015
Messages
16
I figured it out for myself. Since I know the number of sheets, I just used the loop method and it worked very fast:

Sub DeleteRowsTest()

Dim i As Integer

Let x = 0
Do While x < 49

'my macro

x = x + 1
Loop

End Sub
 
Upvote 0

Forum statistics

Threads
1,191,168
Messages
5,985,056
Members
439,936
Latest member
BSR

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