Empty Excel sheet VBA code

pablo1235185

New Member
Joined
Dec 18, 2017
Messages
1
Hello,

I have structured my code in the following way (see below) to erase all the cells that appear with the number: "0". However, it also erases the lines that are empty (without a number or letter) and those i want to keep them. If anyone could help me to identify the mistake under my code tell me where is it. Thanks!!

Dim x, y As Long
Dim feuille As String
Sheets("tdb").Select
y = 3

While Cells(15, y) <> "EP"
feuille = Cells(15, y).Value

Sheets(feuille).Select
x = 1
While Cells(x, 1) <> "x"

If Cells(x, 6) = 0 And Cells(x, 6) = 0 <> "" And Cells(x, 5) = 0 And Cells(x, 5) = 0 <> "" Then
Rows(x).Delete
x = x - 1
End If

x = x + 1
Wend
y = y + 1
Sheets("tdb").Select

Wend

End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi there welcome to the forum.

I think the problem is a couple of extra '=0' bits - I think the if statement should be:

If Cells(x, 6) = 0 And Cells(x, 6) <> "" And Cells(x, 5) = 0 And Cells(x, 5) <> "" Then

This is untested.
 
Upvote 0
In your post you say "erase all the cells" but in your code you use "Rows(x).Delete". Do you want to clear cells or delete rows? Are the zeros you are looking for always in column A? Could you describe in detail exactly what you want to do using a few examples from your data and referring to specific cells, rows, columns and sheets. Perhaps you could post a screen shot of what your data looks like. Look at section B at this link for instructions on how to post a screen shot: https://www.mrexcel.com/forum/board-announcements/127080-guidelines-forum-use.html
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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