Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Worksheet vbs to show 0.00 values as "-"

Posted on 2012-04-13
Medium Priority
189 Views
Hi Expert

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

Thanks
0
Question by:route217
[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

LVL 5

Accepted Solution

gman84 earned 2000 total points
ID: 37843218
``````    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
``````
0

Author Comment

ID: 37844964
Many thanks for the feedback..
0

LVL 81

Expert Comment

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

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
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.
###### Suggested Courses
Course of the Month7 days, 12 hours left to enroll