473,395 Members | 1,681 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

I need a Excel macro to delete zeros only and no zeros containing more numbers.

Hello everybody!

I need your valuable help to get an Excel macro to delete the single zeros only and no the zeros containing numbers like 360, 90, etc., because if I chose the search and replace in the Edit option, then all the zeros containing the numbers 360, 90, 502, etc. will be deleted.

Some nice person helped me with the following code to delete the zeros:
Selection.Replace What:="0", Replacement:="" , but unfortunately this code delete all the zeros including the zeros containing more numbers.

Thank you very mucho for your help.
Feb 5 '08 #1
3 9908
Wagz
11
If you want to use a macro to delete the zeros then you can use the following code
Expand|Select|Wrap|Line Numbers
  1. For Each cell In Selection
  2.     If cell = "0" Then
  3.         cell.Delete
  4.     End If
  5. Next
  6.  
This will go through all of the selected cells and delete any that are zero.

However you can also use search and replace edit option that you described, just make sure to check the "match entire cells contents".

Wagz
Feb 5 '08 #2
kadghar
1,295 Expert 1GB
If you want to use a macro to delete the zeros then you can use the following code
Expand|Select|Wrap|Line Numbers
  1. For Each cell In Selection
  2.     If cell = "0" Then
  3.         cell.Delete
  4.     End If
  5. Next
  6.  
This will go through all of the selected cells and delete any that are zero.

However you can also use search and replace edit option that you described, just make sure to check the "match entire cells contents".

Wagz
That's right, Excel has the option to mach entire cells content, The code wagz wrote will help, but will delete the cell. If what you want is to delete the zero, but keep the cell empty, instead of

cell.delete

use
cell.value = ""

HTH
Feb 6 '08 #3
Hello guys!

I just want to thank you very much for your help!

I am very grateful with you!

I work with statistics most of the time and when I use the function to calculate the average the results vary if the cells have zeros and, of course, that affects the results.

So, the code is doing what I really need!

Have a very nice day!

God bless you!
Feb 6 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: samik_tanik | last post by:
I need to export a datagrid to Excel. I could did this. But, also need to keep the leading zeros in the data. How can I acheive this? Any help would be appreciated. -- Thanking you in...
6
by: Karl Richards | last post by:
I am attempting to delete duplicate rows in a spreadsheet using the Excel object. Does anyone have any idea how to do this? I've looked everywhere that I can find on the Web and have not been...
2
by: RRoma | last post by:
Does anybody know how I can import lists of numbers from Excel into Access without losing the preceeding Zeros??? The field must have a total of 10 digits.... Is this a function of how its saved in...
4
by: Eager VBA Learner | last post by:
I am trying to write an Excel VBA macro that will find all cells in Column A that have numbers (as opposed to text) and delete the entire rows (with the numbers in Column A). As a start, I tried...
2
by: narpet | last post by:
Hello all. I posted this in the Visual Basic forum, but since it has to do with VBA and both Access and Excel share VBA (somewhat) I was hoping someone here would be able to help me... I have a...
6
by: jcf378 | last post by:
hello-- i am having trouble figuring out how to export individual records from an Access 2002 Form into a pre-existing Excel spreadsheet, such that the exported record is merely appended to the...
0
by: shantanu | last post by:
I am trying to convert a macro code to c# that will copy the values of a column and paste to anather through paste special. Everything is working fine but the transpose meathod to paste the column...
2
by: ManuelValdez | last post by:
Hello! I need your help to design an Excel macro to delete zeros only in selected cells. Thank you very much.
3
by: JFKJr | last post by:
Hello everyone, the following is the code which opens an excel file and creates a toolbar button. And, when I click the toolbar button as shown at line #28, the code should call the "Example"...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.