Refine/amend code

Mel Smith

Well-known Member
Joined
Dec 13, 2005
Messages
1,023
Office Version
  1. 365
Platform
  1. Windows
One of our community gave me the following code and I have been trying, without success to refine it and make it work. All I'm trying to achieve is to delete any row between (and including) row 4 to 63 when the value in cell c4:c63 is zero. I do not want nor need a copy of the worksheet. I have the macro stored in my personal .xlsb. I have tried 'commenting out various lines, all to no effect.

Sub Delete_Rows()
'
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

Thanks for your help.

Mel
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
You need to change everywhere it says
VBA Code:
ThisWorkbook
to
VBA Code:
ActiveWorkbook
if you are storing the macro in your personal workbook
 
Upvote 0
Many thanks, Mark. How may I stop a copy of the worksheet being made?

Mel
 
Upvote 0
Thanks for your observation, Mark. I have now achieved the solution I wanted with the following code. I have "commented out" lines two and three:

VBA Code:
For i = 1 To ActiveWorkbook.Worksheets.Count
               'ActiveWorkbook.Worksheets(i).Copy Before:=ActiveWorkbook.Worksheets(i)
               'i = i + 1
               For ii = 63 To 4 Step -1
                    If ActiveWorkbook.Worksheets(i).Cells(ii, 3).Value = 0 Then
                          ActiveWorkbook.Worksheets(i).Cells(ii, 3).EntireRow.Delete
                    End If
               Next
         Next
End Sub

Mel
 
Last edited by a moderator:
Upvote 0
Solution
@Mel Smith
When posting vba code in the forum, please use the available code tags. It makes your code much easier to read/debug. My signature block below has more details. I have added the tags for you this time in post #4. 😊
 
Upvote 0
Hello Peter,

When can I see the instructions to post code in the correct manner?

Mel
 
Upvote 0
When can I see the instructions to post code in the correct manner?
Just as I said in my previous post
My signature block below has more details.
In my signature block at the bottom of each of my posts is the following ..

1665823599222.png
 
Upvote 0

Forum statistics

Threads
1,214,390
Messages
6,119,235
Members
448,879
Latest member
VanGirl

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