Pookiemeister
Well-known Member
- Joined
- Jan 6, 2012
- Messages
- 563
- Office Version
- 365
- 2010
- Platform
- Windows
The following code removes any special characters from Inputbox answer.
So how can I remove certain words that might be entered or combination of letters and numbers from the Inputbox string. Here's an example of what might be entered.
SA Allergy Medicine 15mg 10ct Bottle
So using the bold example entry I would only want to keep Allergy Medicine 15mg from that string and eliminate the rest.
Potential problems/issues to consider
Thank You for any help offered.
VBA Code:
Dim answ as Variant
Do
answ = InputBox("Please enter the amount")
'cancel pressed
If StrPtr(answ) = 0 Then Exit Sub
answ = UCase(answ)
If answ = "" Or IsNumeric(answ) Then
MsgBox "Answer must not be left blank and must contain a letter." & vbCrLf & vbCrLf & "Your answer: " & answ, vbCritical, "Invalid Entry"
Else
Dim special_Characters As String
Dim i As Long
special_Characters = """<,.>?/:;{[}]|\+=_-)(*&^%$#@!'"
For i = 1 To Len(special_Characters)
answ = Replace(answ, Mid(special_Characters, i, 1), "")
Debug.Print answ
If i = Len(special_Characters) Then Exit Do
Next
End If
Loop
SA Allergy Medicine 15mg 10ct Bottle
So using the bold example entry I would only want to keep Allergy Medicine 15mg from that string and eliminate the rest.
Potential problems/issues to consider
- The mg value can change but will always be in this format ###mg or ##mg (No spaces between the number and the letters of the unit of measure(mg) in this example)
- The ct value can change but will always be in this format ###ct or ##ct (No spaces between the number and the letters of the unit of measure(ct) in this example)
- Remove words from text like "SA" or "Bottle" in this example and not just the letters
Thank You for any help offered.