Macro - Deleting rows if cell value contains 0

ChocksterNo1

New Member
Joined
Mar 22, 2011
Messages
24
Hi

I have part of this macro that delete row if cell value = 0 (as shown below)

Dim rng As Range, cell As Range, del As Range
Dim strCellValue As String
Set rng = Intersect(Range("C:C"), ActiveSheet.UsedRange)
For Each cell In rng

strCellValue = (cell.Value)
If InStr(strCellValue, "0") > 0 Then
If del Is Nothing Then
Set del = cell
Else: Set del = Union(del, cell)
End If
End If
Next cell
On Error Resume Next
del.EntireRow.Delete

This only works on 1 worksheet, I have 4 or 5 other worksheets that I need to apply this macro to. If I attach it to the parts for the other worksheets i get the message

compile error: Duplicate declaration in current scope.

was hoping someone could help me.

thanks

Chock
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Ok, I can see that I'm not allowed to use the same variables.

So I was wondering if I put the variables at the top of my macro, could I apply a code that would apply to all my worksheets in the workbook.

thanks

Chock
 
Upvote 0

Forum statistics

Threads
1,224,542
Messages
6,179,421
Members
452,913
Latest member
JWD210

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