Results 1 to 8 of 8

Find and Replace text within string

Threaded View

  1. #1
    Registered User
    Join Date
    04-22-2012
    Location
    Belfast
    MS-Off Ver
    Excel 2007
    Posts
    7

    Find and Replace text within string

    Hi,

    I'm new to this forum and only starting out with VBA in excel and I am wondering if anyone here can help me.

    I am looking for a bit of code to search an external link e.g. U:/Workbooks/[Example123456.xls]Sheet1'!$E$10
    and replace the 123456 only with a cell ref. for example:

    if
    A2 = 654321

    then
    link=U:/Workbooks/[Example654321.xls]Sheet1'!$E$10

    if
    A2 = 555555

    then
    link=U:/Workbooks/[Example555555.xls]Sheet1'!$E$10

    the numbers are always 6 chars long and I need it to do this across serveral sheets

    A1=Sheet1 A1:O40
    A2=Sheet2 A1:O40

    and so on.
    This is what I have currently

    Sub ReplaceFC()
        Dim Rng As Range
        Dim c As Range
        Dim Length As Integer
        Dim LeftSide As Integer
        Dim RightSide As Integer
        With Sheets(3).Range("A:O")
            Set Rng = Range("A1:O" & Range("O65536").End(xlUp).Row)
            For Each c In Rng
                LeftSide = InStr(c, "[")
                RightSide = InStr(LeftSide + 13, c, "]")
                Length = RightSide - LeftSide
                If Length = 13 Then
                    c.Characters(Start:=LeftSide, Length:=Length).Replace = Sheets(2).Range("h2")
                End If
            Next c
        End With
    End Sub
    Many thanks in advance

    Graham
    Last edited by Soulbringer; 06-19-2012 at 12:03 PM.

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