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

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,731
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 can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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,223,885
Messages
6,175,179
Members
452,615
Latest member
bogeys2birdies

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