+ Reply to Thread
Results 1 to 8 of 8

Need to search cell for text string and paste text in based on finding

  1. #1
    Registered User
    Join Date
    06-29-2014
    Location
    Falls Church, VA
    MS-Off Ver
    2007
    Posts
    4

    Need to search cell for text string and paste text in based on finding

    Hi,

    I need to create a macro to do the following:

    Search the activecell for a text string (a), and then either paste in text string (b) at the end of the cell if (a) is found, or text string (c) if (a) is not found.

    For example, if the activecell has "AA/" in it, I want the cell to become "AA/01" (pasting in "01" at the end), and if the cell has just "AA" in it, I want it to still become "AA/01" (pasting "/01" at the end). The macro will be linked to a commandbutton.

    Thanks for any advice.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Need to search cell for text string and paste text in based on finding

    Maybe:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    06-29-2014
    Location
    Falls Church, VA
    MS-Off Ver
    2007
    Posts
    4

    Re: Need to search cell for text string and paste text in based on finding

    Thanks for your response.

    Is there a way to do this just searching for a string (the "/") using an if/then statement and then do a paste function based on the result? My paste code is:

    Private Sub CommandButton18_Click()
    ActiveCell.FormulaR1C1 = ActiveCell.Value & "k"
    End Sub

    That adds a "k" onto the active cell when I push the corresponding button.

    So basically I want to set up the macro with two different paste commands, based on if that "/" is already in the cell or not. I just want to search the active cell when I push the button, not more than that.

    Thanks again.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Need to search cell for text string and paste text in based on finding

    Maybe:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-29-2014
    Location
    Falls Church, VA
    MS-Off Ver
    2007
    Posts
    4

    Re: Need to search cell for text string and paste text in based on finding

    That works for when there is a /, thanks much.

    Is there a way to enter a different text string (let's say a j instead of a k) if the "/" is NOT found in the cell? Maybe using an ELSE command?

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Need to search cell for text string and paste text in based on finding

    Like this:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    06-29-2014
    Location
    Falls Church, VA
    MS-Off Ver
    2007
    Posts
    4

    Re: Need to search cell for text string and paste text in based on finding

    Thanks very much!

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Need to search cell for text string and paste text in based on finding

    You're welcome and thanks for the rep!

    You can now mark this thread as solved - go to Thread tools up top.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] To search specific text in a cell that contains text string
    By mikail in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-15-2013, 03:02 PM
  2. Replies: 1
    Last Post: 04-08-2013, 07:07 PM
  3. [SOLVED] Search multiple worksheets for Text String, copy and paste entire row into new worksheet
    By spulliam2000 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-15-2013, 07:52 PM
  4. Update Combo/List Box based on Text box search string
    By megha_gharote in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-10-2013, 06:16 AM
  5. Replies: 3
    Last Post: 07-25-2012, 07:54 AM

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