• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Macros for deleting 0

srinidhi

Active Member
Hi,


I have a set of numbers like


1234

3446

0

3050

3450

0456

0

0

890890


I want to delete the rows which contains only 0


Below I have pasted the macros but it is deleting 0 from the numbers also. I just want to delete the row which has only 0 and does not have any other number with it.


Private Sub Delete()


Dim intRow

Dim intLastRow

intLastRow = Range("1000").End(xlUp).Row


For intRow = intLastRow To 1 Step -1


Rows(intRow).Select

If Cells(intRow, 1).Value = 0 Or Cells(intRow, 1) = "" Then

Cells(intRow, 1).Select

Selection.EntireRow.Delete


End If


Next intRow


Range("A1").Select


End Sub
 
Srinidhi


Your values are not numbers but are in fact Text, you can see that because the number in your list 0456 shouldn't have a leading zero


Running the macro must be reading the values and then saving them back as numbers.


If you want to maintain the leading zero instead of checking Cells(intRow, 1).Value=0 try check if Cells(intRow, 1).Text ="0" that works
 
Back
Top