+ Reply to Thread
Results 1 to 2 of 2

Delete String if in other Textbox

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-23-2010
    Location
    Staten Island, NY
    MS-Off Ver
    Excel 2003
    Posts
    242

    Delete String if in other Textbox

    Say I have 2 textboxes called textboxA and TextboxB. TextboxA will have a long string and TextboxB will have a small string. If I find TextboxB in TextboxA's String - then I want to remove that piece from TextboxA. Is this possible? here is an example:

    TextboxA: Tuna, Tongol 4/3 lb
    TextboxB: 4/3 lb

    I want to remove what is in TextboxB from TextboxA so I would get this:

    TextboxA: Tuna, Tongol
    TextboxB: 4/3 lb

    the string that needs to be removed from TextboxA will not always be at the end of it and will not always contain numbers. Sometimes it will be all letters sometimes letters and numbers, etc.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Delete String if in other Textbox

    You can use the REPLACE function to do that. Read up on the function, then play around with it, something like:


    If InStr(TextBoxA.Value, TextBoxB.Value) > 0 Then
        TextBoxA.Value = Trim(Replace(TextBoxA.Value, TextBoxB.Value, ""))
    End If
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1