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

x
?
Solved

Format all numbers with NumberFormat '0.0' using VBA

Posted on 2011-09-02
5
Medium Priority
?
494 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 2000 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 2000 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

Industry Leaders: 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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

670 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