Excel VBA Macro Convert Number to Percentages

August 8, 2019 at 12:34:12
Specs: Windows 10 Enterprise
Good afternoon,
I am wondering if it is possible to make a vba macro where i have columns in random order from numbers 1 to 5. Each number should represent a percentage meaning ( 7 to 4 = 100%, 3 = 75%, 2=50%, 1 = 25%, 0=0%). I would like to have a macro where the rows with all of these different numbers give you the final total percentage after adding all of the numbers from 1 to 5. Excel looks like this. The problem is that having some "N/A makes it difficult I want the macro to ignore the"N/A and just evaluate the percentages from the cells that actually have number/values.

July #1 July #2 July #3 July #4 Total Score
5 5 6 5 100%
5 3 5 3
#N/A #N/A #N/A #N/A
5 #N/A 5 #N/A

The (July parts are the titles)
Then first row is an example of how its suppose to look like with the hundred percent at the end.


See More: Excel VBA Macro Convert Number to Percentages

Reply ↓  Report •

#1
August 19, 2019 at 11:39:13
Try This Code:

Sub MACRO2()
For Each cell In Selection
With cell
.Value = .Value / 100
.NumberFormat = "0.0%"
End With
Next
End Sub

OR

Sub tst3()
With Range(("B2:F35")
.Value = Evaluate("INDEX(" & .Address & "/100,,)")
.NumberFormat = "0.0%"
End With
End Sub

Mike
Office 365 Enterprise E5 Expert



Reply ↓  Report •
Related Solutions


Ask Question