+ Reply to Thread
Results 1 to 5 of 5

Replace Text in a Text String

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Replace Text in a Text String

    I have a file the details the filepath to thousands of folders in the format:

    C:\Client Jobs\Test\East\Folder1
    C:\Client Jobs\Test\East\Folder2
    C:\Client Jobs\Test\East\Folder3

    C:\Client Jobs\Test\West\Folder1
    C:\Client Jobs\Test\West\Folder2
    C:\Client Jobs\Test\West\Folder3

    etc... (see attached)

    The number of folders can vary from one to n. I would like to be able to run a macro that replaces every instance 'Folder1' with different text, e.g. 'Accounts', 'Folder2' with say 'Reports' and so on, so it basically cycles through 'Folder1' to 'FolderN' replacing the text with what ever I define. I know I could do this with a simple Find/Replace, but this will be a repetitive requirement an a macro approach would dramatically speed things up.

    Is this possible?

    Many thanks
    Attached Files Attached Files
    Thanks,
    HangMan

    You can say "Thank you!" by clicking Add Reputation below the post.
    Please, mark your thread [SOLVED] if you are happy with the solution.

  2. #2
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Replace Text in a Text String

    Try,
    Columns("A").Replace "\Folder1", "\Accounts", xlPart, , True
    changing the replacement text as needed in the script.

  3. #3
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Replace Text in a Text String

    And a bit more specified:
    Sub test()
        Dim i As Integer
        For i = 1 To 6
            ActiveSheet.UsedRange.Replace "\Folder" & i, Choose(i, "Accounts", "Reports", "NewFolder3", "NewFolder4", "NewFolder5", "NewFolder6"), xlPart, , True
        Next
    End Sub

  4. #4
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Replace Text in a Text String

    Hi berlan,

    I removed the \ before Folder and it worked like a charm, perfect...

    Many thanks for your help

  5. #5
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Replace Text in a Text String

    Glad it worked, you're welcome!

+ 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. Lookup & replace specific text in a text string
    By Haha88 in forum Excel General
    Replies: 1
    Last Post: 07-13-2015, 06:06 PM
  2. Replace text string in a cell and retain rich text formatting (Excel 2013)
    By CharlieBear in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 04-15-2015, 04:39 PM
  3. Macro for adding text, spacing, and a replace in a text string.
    By scapegoat9595 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-17-2013, 10:44 AM
  4. [SOLVED] Find partial text string within another text string return original text into cell.
    By mikey42979 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 06-17-2013, 02:58 PM
  5. replace some text on a string in a cell
    By ELFM in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-09-2013, 12:24 AM
  6. [SOLVED] VBA to Search a Text String, Find a Value listed in another column and replace the text
    By Jschrod303 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-16-2012, 08:56 PM
  7. Replace Text in a String
    By newbieexceldude in forum Excel General
    Replies: 4
    Last Post: 03-29-2010, 10:55 PM

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