Code for currency value in Textbox to now also allow N/A

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,602
Office Version
  1. 2007
Platform
  1. Windows
On my userform i have this in a textbox.
Currently it will only allow a currency value.
But i now have a reason to have it allow N/A or a currency value.


Anything other than a currency value then pops up the Message.

Please advise thanks.

VBA Code:
Private Sub TextBox5_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    If Len(TextBox5) = 0 Then Exit Sub
    If IsNumeric(TextBox5) Then
        TextBox5 = Format(TextBox5, "£#,##0.00")
    Else
        MsgBox "THE QUOTED VALUE MUST BE £ FIGURE.", vbCritical, "THERE WAS NO £ IN QUOTED FIELD MESSAGE"
        TextBox5 = ""
        Cancel = True
    End If
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Give this a try. I did not set up a new file to try to match yours to test this.
Rich (BB code):
Private Sub TextBox5_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    If Len(TextBox5) = 0 Then Exit Sub
    If IsNumeric(TextBox5) Then
        TextBox5 = Format(TextBox5, "£#,##0.00")
    ElseIf TextBox5 <> "N/A" Then
        MsgBox "THE QUOTED VALUE MUST BE N/A OR £ FIGURE.", vbCritical, "THERE WAS NO £ IN QUOTED FIELD MESSAGE"
        TextBox5 = ""
        Cancel = True
    End If
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,221,444
Messages
6,159,912
Members
451,601
Latest member
terrynelson55

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