Verify that Textbox Value is Percentage

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
701
Office Version
  1. 365
Platform
  1. Windows
I'm trying to validate that the value of a textbox is a percentage. I use IsNumeric and IsEmpty for other textboxes, but there doesn't appear to be a IsPercentage function that I can use. I'm horrible with everything related to Math, so I'm not sure if I need to do some sort of equation to determine if the textbox is formatted as a percentage or not.

Here's the code that turns the value into a percentage.
Code:
Private Sub txt_BodyFat_Exit(ByVal cancel As MSForms.ReturnBoolean)'Formats the field as a percentage.
If Not Len(Me.txt_BodyFat.Value) = 0 And IsNumeric(Me.txt_BodyFat.Value) Then
    Me.txt_BodyFat = Format(Val(Me.txt_BodyFat) / 100, ".#0%")
Else
    MsgBox "Please enter a valid Body Fat value, using numbers only."
End If
End Sub

I need to verify that the value is a percentage when the EU clicks a command button, so that some other value doesn't map over to the destination sheets.

Thoughts?
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,214,786
Messages
6,121,546
Members
449,038
Latest member
Guest1337

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