How can I convert a pecentage number to percentage text

Hernan_g_f

New Member
Joined
Jul 26, 2022
Messages
22
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I have the following percentage numbers in column A and I want to convert them to text using vba

A B
1 20 % = worksheetfunction.? Cells(i,1).Value?? text (in %)
2 10 %
3 15 %

How can I do it?

Thanks i advance,
Hernán
 

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.
VBA Code:
Function PercentToWords(ByVal percentValue As Double) As String
    Dim units As String
    Dim tens As String
    Dim result As String
   
    If percentValue < 0 Then
        PercentToWords = "Invalid input"
        Exit Function
    End If
   
    ' Define word forms for units and tens
    units = "Zero One Two Three Four Five Six Seven Eight Nine"
    tens = "Ten Twenty Thirty Forty Fifty Sixty Seventy Eighty Ninety"
   
    ' Convert the percentage to words
    If Int(percentValue * 100) < 10 Then
        result = Split(units, " ")(Int(percentValue * 100))
    Else
        result = Split(tens, " ")(Int(percentValue * 100) \ 10 - 1)
        If Int(percentValue * 100) Mod 10 <> 0 Then
            result = result & " " & Split(units, " ")(Int(percentValue * 100) Mod 10)
        End If
    End If
   
    ' Return the result
    PercentToWords = result & " percent"
End Function
then use:
=PercentToWords("A1") or any cell that contains value you need to convert
 
Upvote 0
Solution

Forum statistics

Threads
1,223,907
Messages
6,175,300
Members
452,633
Latest member
DougMo

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