+ Reply to Thread
Results 1 to 12 of 12

Search & Replace InString

  1. #1
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Search & Replace InString

    Hi all,

    I'm having somewhat of a difficult time trying to put some code together to
    search for a string of characters matching a specific arrangement.

    The specific arrange would be any numerical value followed by an alpha character.
    such as: (1abc,12abc,123abc, 1234abc, 1234nabc....) n= any numeral of any length
    abc = any alpha string of any length.

    I'd would like to start the search from the LEFT(1abc,1), and for the only the
    first case found,

    the a space " " needs to be put between the numeric and alpha characters.
    such as: (1 abc,12 abc,123 abc, 1234 abc, 1234 nabc....)
    I don't know if these would be easier using a "case select" code
    or something like

    Please Login or Register  to view this content.
    ...above code not working.

    Any help is appreciated.

    Thanks,

    BDB
    Last edited by bdb1974; 05-04-2010 at 09:24 AM.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Search & Replace InString

    You could try logic like this.

    Please Login or Register  to view this content.
    Martin

  3. #3
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: Search & Replace InString

    Formula approach

    Please Login or Register  to view this content.
    Люди, питающие благие намерения, как раз и становятся чудовищами.

    Regards, ?Born in USSR?
    Vusal M Dadashev

    Baku, Azerbaijan

  4. #4
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Search & Replace InString

    Thanks guys, but something is still not right.

    mrice, The code as is did not change anything. I've been trying to figure out what's not right with it. Yet to correct.

    Here's another attempt which does nothing.
    Please Login or Register  to view this content.
    Forum Guru, I'm not real sure how I would apply the formula to my code.
    If you can supply some code that I could use, then I'd be more than happy to try it.

    BDB
    Last edited by bdb1974; 04-30-2010 at 06:21 PM.

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Search & Replace InString

    Hello BDB,

    This is quite easy to do using Regular Expressions. Here is an example.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  6. #6
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Search & Replace InString

    Thanks Leith,

    I'm not sure what's happening.
    I got your script to work in a worksheet cell. But, when I attempt to place it into the userform where it's needed, I'm not getting any change/corrections to occur.

    Please Login or Register  to view this content.
    :/

    BDB

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Search & Replace InString

    Hello BDB,

    Do you want the modified text from the TextBox to be transfered to a worksheet cell or just displayed in the TextBox?

  8. #8
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Search & Replace InString

    The modified text needs to be transferred to a worksheet cell.

    Please Login or Register  to view this content.
    Thanks,

    BDB
    Last edited by bdb1974; 05-03-2010 at 02:49 PM.

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Search & Replace InString

    Hello BDB,

    This should work. Try it out and let me know what happens. The contents of the text box will remain unchanged, but the worksheet cell will show the corrected text.
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Search & Replace InString

    Leith,
    Still no change.
    So, I put together a test workbook with a userform, just with your code.
    And again no change.

    BDB
    Attached Files Attached Files

  11. #11
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Search & Replace InString

    Got It!

    Here it is.
    Please Login or Register  to view this content.

    Thanks Leith for your Help.


    BDB

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Search & Replace InString

    Hello BDB,

    The code to create the RegExp has to be a standard module. Here is the code now. These changes have been made to the attached workbook.

    Module1 Code
    Please Login or Register  to view this content.


    CommandButton2 Code
    Please Login or Register  to view this content.
    Attached Files Attached Files

+ 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