Searching for " in userform textbox input

supdawg

Well-known Member
Joined
Mar 18, 2007
Messages
608
This one should be easy. Just trying to apply some crude check on a userform to ensure that the end users are entering the text as

19"
20"
22"
etc

key is the " at the end

Here's what I've done to check that its 3 digits.

Code:
'check for a part size length
If Len(Me.TextSize.Value) <> 3 Then
  Me.TextSize.SetFocus
  MsgBox "Part Size is not 3 digits. Please ensure it's entered as 19"""
  Exit Sub
End If

How can I check the string to ensure it has the " at the end? I've tried Find, but it doesn't appear to work with ".
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
How about adding it if it's missing?
Code:
Dim blnOK As Boolean

blnOK = False
If (IsNumeric(Left(Me.TextSize.Value,2)) And (Len(Me.TextSize.Value) = 2) Then
        Me.TextSize.Value = Me.TextSize.Value & Chr(34) '//Add Quote
	blnOK = True
ElseIf (IsNumeric(Left(Me.TextSize.Value,2)) And (Len(Me.TextSize.Value) = 3)  And (Right(Me.TextSize.Value,1) = Chr(34)) Then
        blnOK = True
End If

End If
If Not blnOK then
    Me.TextSize.Value = ""
    Msgbox "Part size must be a two digit number followed by a quote"
    Me.TextSize.SetFocus
End If

This way your input works for both:
22
22"

Otherwise per your original spec:
Code:
Dim blnOK As Boolean

blnOK = False
If Len(Me.TextSize.Value) = 3 Then
        If IsNumeric(Left(Me.TextSize.Value,2)) And Right(Me.TextSize.Value,1) = Chr(34) Then
            blnOK = True
	End If
End If

If Not blnOK then
    Me.TextSize.Value = ""
    Msgbox "Part size must be a two digit number followed by a quote"
    Me.TextSize.SetFocus
End If
 
Last edited:
Upvote 0
Thank you.. Testing your first solution, but I get red lines on If and ElseIf

I keep looking at the code, I don't see what's missing other than there are two End If statements?

Edit: Nevermind, I got it working, it was missing a couple of closing parentheses. :)

Your solution is much better, that way they won't need to worry about entering the quote.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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