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

[TABLE="width: 72"]
<colgroup><col width="72" style="width:54pt"> </colgroup><tbody>[TR]
[TD="width: 72"] Range("D5:G64,L5:O64").Select[/TD]
[/TR]
[TR]
[TD] Selection.NumberFormat = "0.0%"[/TD]
[/TR]
[TR]
[TD] .Value = .Value[/TD]
[/TR]
[TR]
[TD] [/TD]
[/TR]
[TR]
[TD] Range("H5:K64,P5:S64").Select[/TD]
[/TR]
[TR]
[TD] With Selection[/TD]
[/TR]
[TR]
[TD] Selection.NumberFormat = "General"[/TD]
[/TR]
[TR]
[TD] .Value = .Value[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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