How to remove decimal numbers out of only 100%

edge37

Board Regular
Joined
Sep 1, 2016
Messages
57
Office Version
  1. 2021
Platform
  1. Windows
Greeting! I have this question: I have a cell in which I need to show averages of grades, that includes 2 decimals, as percents, but I would like to format the cell for, when I have a 100% average, all decimals are removed, the rest of numbers will keep their decimals, EXCEPT 100%, which I want it to show without any decimals..
I'm using a VBA code and a formula for showing the averages in just one cell when I click a student's name:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Range("AM9").Value = ActiveCell.Value
End Sub
Code:
=CELL("address")
In Format Cell>Number>Custom, I use 0.00%;;""
In the cell I use the formula:
Code:
=IFERROR((VLOOKUP($AM$9,$B$9:$Z$33,19,FALSE)/100),0)
Is this possible? Thanks for your help

Please advice if I have to send anything else to fully explain myself. The image illustrates the problem.
 

Attachments

  • Screenshot_21.jpg
    Screenshot_21.jpg
    129.3 KB · Views: 8

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
In your VBA code; which cell is ActiveCell?
 
Upvote 0
I am confused. That code will literally just replace the cell value with the cell value. Like saying 3 = 3. Are you looking for something like this?
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = Range("AM9").Address Then
    If Target.Value = 1 Then
        Target.NumberFormat = "0%"
    End If
End If
End Sub
 
Upvote 0
If those are whole numbers in those cells, why not use a different # format:
[=100]0\%;General
 
Upvote 0
If those are whole numbers in those cells, why not use a different # format:
[=100]0\%;General
This # format returns the average fine, but the % sign is lost in all average values except with 100, only when the average is 100 it appears as 100% (with % sign). I need all average values to show with the % sign as well. Thank you.
 
Upvote 0
I am confused. That code will literally just replace the cell value with the cell value. Like saying 3 = 3. Are you looking for something like this?
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = Range("AM9").Address Then
    If Target.Value = 1 Then
        Target.NumberFormat = "0%"
    End If
End If
End Sub
Thank you. Yes, the code is just for showing what I want in that particular cell, I use it along with =CELL("address") for many desired effects in my worksheet as well. Anyway, I try to substitute my code with yours, but I notice that all my other actions stop working and the problem that I want to solve still is not solved. In my unexperienced mind, I thought that solving the problem I'm having didn't have anything to do with that particular code, but again, how could I know. Thank you again.
 
Upvote 0
Right now I have solved the problem by using, in another cell, the formula:
VBA Code:
=IF(AM14=100.00%,"100%",AM14)
with the # format: 0.00%;;"" and redirecting information to that cell to have the effect I'm looking for, but I still would like to know if the former cell I could could have the effect that I was looking for. I thank you all very much for your kind help.
 
Upvote 0
I think so. Try this:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("AM9").Value = ActiveCell.Value
If Range("AM9") = 1 Then
        Range("AM9").NumberFormat = "0%"
End If
End Sub
 
Upvote 0
I think so. Try this:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("AM9").Value = ActiveCell.Value
If Range("AM9") = 1 Then
        Range("AM9").NumberFormat = "0%"
End If
End Sub
Thank you again Skybot, but again it's not working for me, the 100% still shows 100.0%. I included an image to illustrate the worksheet using your VBA code already. Thanks again..
 

Attachments

  • Screenshot_22.jpg
    Screenshot_22.jpg
    116.8 KB · Views: 5
Upvote 0

Forum statistics

Threads
1,215,112
Messages
6,123,162
Members
449,099
Latest member
afishi0nado

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