Solved

Format all numbers with NumberFormat '0.0' using VBA

Posted on 2011-09-02
5
481 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
  • 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

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

Suggested Solutions

Title # Comments Views Activity
consolidate from multiple folders 5 39
Tags from access to excel 3 27
highlight duplicate entry 16 27
Excel callender with date slider 5 25
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 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…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

911 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

19 Experts available now in Live!

Get 1:1 Help Now