Solved

Delete all zeros in column A using VBA

Posted on 2011-09-04
7
449 Views
Last Modified: 2012-05-12
Dear Experts:

I would like to achieve the following using VBA:

Delete all zeros (0) in column A of the active worksheet regardless of their formatting, i.e. zeros formatted as text or number.

Help is much appreciated.  Thank you very much in advance.

Regards, Andreas
0
Comment
Question by:AndreasHermle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 18

Accepted Solution

by:
krishnakrkc earned 500 total points
ID: 36480417
Hi,

Try

Sub kTest()

    With ActiveSheet.Columns(1)
        .Replace "0", "", 1
        '//if you want to delete the rows uncomment the following 3 line

'        On Error Resume Next
'        .SpecialCells(4).EntireRow.Delete
'        On Error GoTo 0
    End With

End Sub

Kris
0
 
LVL 5

Expert Comment

by:slycoder
ID: 36480748
In Excel 2007 and above - you can Hide all zeros in the worksheet with - File -  Options - Advanced - Display Options For This Worksheet -  and uncheck: Show a Zero in Cells that have a Zero Value.
0
 

Author Comment

by:AndreasHermle
ID: 36480902
Hi Kris,

thank you very much for your swift help. I am afraid to tell you that nothing happens when running your code. My requirements may have been a little bit to vague.

The following code which I managed to set up myself does what I want. It is a little bit slow though. And I wonder that all Zeros are deleted even if they are formatted as numbers.

Regards, Andreas


Sub kTestfinal()

Dim cel As Range

For Each cel In ActiveSheet.Columns(1).Cells
If cel.Value = "0" Then
cel.ClearContents
End If
Next cel

Open in new window

0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:AndreasHermle
ID: 36480904
Hi slycoder:

thank you very much for your feedback. I am aware of this feature, but it is regrettably of no use for my requirements.

Regards, Andreas
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 36481087
Andreas,

Do you mean "clear" the cell, or delete the cell?

If delete, do you mean delete just that cell, or the whole row?

If delete just that cell, do you want to shiftthe cells below it up, or the cells to the right leftward?

Patrick
0
 

Author Comment

by:AndreasHermle
ID: 36481196
Hi Patrick:

I mean 'clear' the cell

Thank you, Regards, Andreas
0
 
LVL 18

Expert Comment

by:krishnakrkc
ID: 36482192
Hi

It works fine for me regardless of their formatting.

Are you able to do this manually ?

Hit Ctrl + H
Find what: 0
Leave 'Replace with' box empty
Replace All
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question