Macro to delete rows dependent on cell value

Mel Smith

Well-known Member
Joined
Dec 13, 2005
Messages
1,023
Office Version
  1. 365
Platform
  1. Windows
I have a several (almost identical) spreadsheets that I regularly need to delete rows based upon the value displayed in each cell within the range C4:C63. The cells in this row get their value via a link from another workbook. What I am trying to achieve is: if cell C4 shows 0 then delete row and so on down to and including row 63. I would like, if possible, for this macro to be available every time I open Excel so that I can call it whenever I need it rather than re-writing it every day.

Thanks for your help.

Mel
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Flashbond,

I've copied your code and it does create a copy of the worksheet, which I don't need but it does not delete the rows where cell C4, C5 etc. to cell C63 that display a zero. The zero is the result of: =IF('Sign in to your Microsoft account)

Georgiboy - Personal Macros - thankyou!

Mel
 
Upvote 0
Sorry there is a mistake in the code,
Try like this:
VBA Code:
Private Sub Workbook_Open()
         For i = 1 To ThisWorkbook.Worksheets.Count
               ThisWorkbook.Worksheets(i).Copy Before:=ThisWorkbook.Worksheets(i)
               i = i + 1
               For ii = 63 To 4 Step -1
                    If ThisWorkbook.Worksheets(i).Cells(ii, 3).Value = 0 Then
                          ThisWorkbook.Worksheets(i).Cells(ii, 3).EntireRow.Delete
                    End If
               Next
         Next
End Sub
 
Last edited by a moderator:
Upvote 0
Thanks for the amendment, Flashbond. Which line(s) can I remove to stop making a copy of the worksheet?
 
Upvote 0
Hi Flashbond,

I "commented" that line out and it failed at the line: If ThisWorkbook.Worksheets(i).Cells(ii, 3).Value = 0 Then

Any thoughts?

Mel
 
Upvote 0

Forum statistics

Threads
1,215,198
Messages
6,123,593
Members
449,109
Latest member
Sebas8956

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