macro question

T

Terry

I am trying to modify a macro so that the cell is
formatted with a percent and 2 decimal places. The macro
right now inserts a number formatted with a percent but
no decimal places into B3. The code is as follows:

Range("B3").Select
Selection.Style = "Percent"

Can someone help me with this. Thanks in advance.
 
D

Dave Peterson

Another option would have been to change the Percent style number format to show
2 decimal places:

Format|style|percent|click on Modify
and change it to 2 decimals.

These styles live with the workbook that they're in--it won't affect other
workbooks (well, unless you merge styles)
 
G

Gord Dibben

Terry

Sub NumToPercent()
Dim c As Range
For Each c In Selection
a = c.Value
If IsNumeric(a) Then
If a <> 0 Then a = a / 100
c.Value = a
c.NumberFormat = "0.00%"
End If
Next
End Sub

Gord Dibben Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top