Format Text to Percent & Value VBA

billandrew

Well-known Member
Joined
Mar 9, 2014
Messages
743
Hello All

trying to format one range of text to a percentage and a different range to a value. Code I am using below

Range("D5:G64,L5:O64").Select
Selection.NumberFormat = "0.0%"
.Value = .Value
Range("H5:K64,P5:S64").Select
With Selection
Selection.NumberFormat = "General"
.Value = .Value

<colgroup><col width="72" style="width:54pt"> </colgroup><tbody>
</tbody>
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi ,

See if this works :
Code:
Public Sub temp()
           With Range("D5:G64")
                .NumberFormat = "0.0%"
                .Value = .Value
           End With


           With Range("L5:O64")
                .NumberFormat = "0.0%"
                .Value = .Value
           End With


           With Range("H5:K64")
                .NumberFormat = "General"
                .Value = .Value
           End With
           
           With Range("P5:S64")
                .NumberFormat = "General"
                .Value = .Value
           End With
End Sub
 
Upvote 0
I changed the code a bit to the following. This does not work, can anyone explain why?

With Range("D5:G64,L5:O64")
.NumberFormat = "0.0%"
.Value = .Value
End With






With Range("H5:K64,P5:S64")
.NumberFormat = "0.0"
.Value = .Value
End With
 
Upvote 0
Actually the percentage is incorrect. If the value is 27.2039 the result percentage is 272 percent. The result should be 27.2 percent
 
Upvote 0
Hi ,

When you include two ranges in the same Range statement , and then use the line of code :

.Value = .Value

both these ranges acquire the same values , which is why I separated them into two separate statements.

Percentage is when a number is divided by 100 ; thus , if you have a value such as 5% , it means 5 divided by 100 , which is 0.05

Conversely , when you have a value which needs to be converted to a percentage , you need to multiply by 100 ; thus , given your value of 27.2039 , the percentage value would be 2720.39 percent.

If you want a result of 27.2% , the actual value would have to be 0.272
 
Upvote 0
Hi ,

Instead of the line of code :

Code:
.Value = .Value

you could have :

Code:
.Value = Application.Evaluate("=" & .Address & "/" & 100)
 
Upvote 0

Forum statistics

Threads
1,215,850
Messages
6,127,282
Members
449,373
Latest member
jesus_eca

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top