remove certain words from textbox

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
563
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
As of now, I have two textboxes on a userform. The second textbox(txtbxTRYD)just copies the value of the first textbox. Would it be possible to remove part of the word(s) of the first string. Here's an example:
S/A Aspirin 5mg 20ct

So using the above example in bold, I would only need the words Aspirin 5mg in the second textbox. I tried using both Replace and Split but I am not really familiar with Replace. The main problem is that the text will change depending on the different product names. The only thing I can come up with is using If...Then statements to achieve this. I just wanted to make sure that there wasn't an easier option. Below is that code. Thank You.

VBA Code:
Private Sub txtbxPrdctName_Change()
    Me.txtbxPrdctName = StrConv(Me.txtbxPrdctName.Value, vbProperCase)
    Me.txtbxTYRD.Value = Me.txtbxPrdctName.Value
End Sub

Private Sub txtbxPrdctName_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    
    If Len(txtbxPrdctName.Value) > 2 Then
        Me.txtbxPrdctName.Value = StrConv(Me.txtbxPrdctName.Value, vbProperCase)
        MsgBox Me.txtbxTYRD.Value
    End If
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
For anyone to be able to help you, some further information would be helpful

Transforming S/A Aspirin 5mg 20ct (long) to Aspirin 5mg (short) is only one example and it is possible to give you several ways to achieve that without any of them solving your issue with the rest of the data.

Can you explain what the "bigger" picture is and what you are trying to achieve
eg
I have a list of "long" names and want VBA to replace them with their equivalent "short" names
or
I am looking to "top and tail" strings based on a list of rules and values

Given the nature of the product, I suggest you use XL2BB to provide sample "before" and "after" strings so that the real complexity of your issue is appreciated from the beginning
- make sure that data you provide covers the breadth of issues likely to be faced
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,738
Members
448,988
Latest member
BB_Unlv

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