Solved

Worksheet vbs to show 0.00 values as "-"

Posted on 2012-04-13
3
184 Views
Last Modified: 2012-04-13
Hi Expert

How would you use vba to make all the values in a range of cells
From 0.00 to "-"....

Thanks
0
Comment
Question by:route217
3 Comments
 
LVL 5

Accepted Solution

by:
gman84 earned 500 total points
ID: 37843218
The follow should help you:
    Dim iCol As Integer
    Dim iRow As Integer
    
    For iRow = 1 To 10
        For iCol = 1 To 1
            If (IsNumeric(Cells(iRow, iCol)) And Cells(iRow, iCol) = 0) Or Trim$(Cells(iRow, iCol)) = vbNullString Then
                Cells(iRow, iCol) = "-"
            End If
        Next
    Next

Open in new window

0
 

Author Comment

by:route217
ID: 37844964
Many thanks for the feedback..
0
 
LVL 81

Expert Comment

by:byundt
ID: 37845152
I realize that the question has already been answered, but you could more simply change the numeric format to display 0 as -.

Range("A2:A100").NumberFormat = "0.00;-0.00;-;@"             'Puts the hyphen at far right
Range("A2:A100").NumberFormat = "0.00;-0.00;-_0_0;@"      'Puts the hyphen where decimal point goes

The benefit of changing the numeric format (rather than the value in the cell) is that you can still use the cell value in other arithmetic computations. Changing the value in the cell to text (as in the Accepted Solution) can sometimes cause an error value to result in subsequent calculations.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

912 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now