Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Changing the format of numbers using the Excel object in VB

Posted on 2000-04-03
3
Medium Priority
?
134 Views
Last Modified: 2011-09-20
How can I change the decimal point of numbers in an Excel spreadsheet through VB? The code I'm using is this:

.Range("B6:I16").Value.NumberFormat = "#0.00"

which only changes the display of numbers but not the value, which is still in it's original form.
0
Comment
Question by:wsteph
3 Comments
 

Author Comment

by:wsteph
ID: 2680567
I used the wrong code fragment, it should be:

..Range("B6:I16").NumberFormat = "#0.00"
0
 
LVL 17

Expert Comment

by:calacuccia
ID: 2680647
Hi WSteph,

If you need to round the numbers as displayed by your previous command, use this little code part (preceded by .)

For Each Cell In .Range("B6:I16")
Cell.Value = Application.WorksheetFunction.Round(Cell, 2)
Next Cell

The 'Application' is the running excel instance in this example, replace it by what you have as an Excel application if you're operating from outside.

Hope this helps

Calacuccia
0
 
LVL 1

Accepted Solution

by:
riduce earned 150 total points
ID: 2680997
Here is you're answer
add this to you're code:

ActiveWorkbook.PrecisionAsDisplayed = True
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

972 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