Solved

Format all numbers with NumberFormat '0.0' using VBA

Posted on 2011-09-02
5
489 Views
Last Modified: 2012-05-12
Dear Experts:

On the active worksheet I would like to search for ALL numeric values (even if they have been entered as text) and apply the following format: NumberFormat '0.0', ie. format all numeric values as numbers with one decimal place.  

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
  • 3
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
nutsch earned 500 total points
ID: 36475726
Try this,

Thomas
Sub agdsagds()
Dim cl As Range

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False


For Each cl In ActiveSheet.UsedRange.SpecialCells(xlCellTypeConstants)
    If IsNumeric(cl) Then
        cl.NumberFormat = "0.0"
        cl.Value = CDbl(cl.Value)
    End If
Next

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True

End Sub

Open in new window

0
 

Author Comment

by:AndreasHermle
ID: 36476231
Hi Thomas,

great, thank you very much for your professional help. One more thing, how would this macro to be tweaked if not the used range would be used but a workbook level scope name, named 'MyRange'

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

Regards, Andreas
0
 
LVL 39

Assisted Solution

by:nutsch
nutsch earned 500 total points
ID: 36476236
You'd replace

For Each cl In ActiveSheet.UsedRange.SpecialCells(xlCellTypeConstants)

by

For Each cl In activeworkbook.range("MyRange").SpecialCells(xlCellTypeConstants)

Thomas
0
 

Author Closing Comment

by:AndreasHermle
ID: 36476262
Great, Thomas. I really appreciate  you swift and professional support.

Thank you very much. Regards, Andreas
0
 
LVL 39

Expert Comment

by:nutsch
ID: 36476270
Glad to assist. Thanks for the kind words.

Thomas
0

Featured Post

Independent Software Vendors: 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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

729 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