Solved

Worksheet vbs to show 0.00 values as "-"

Posted on 2012-04-13
3
187 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
[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
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
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 …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
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…

752 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