Verify that Textbox Value is Percentage

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
714
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

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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