+ Reply to Thread
Results 1 to 9 of 9

Search and Replace Part of Formulas

Hybrid View

alainsi Search and Replace Part of... 06-23-2009, 11:50 AM
Greg M Re: Search and Replace Part... 06-24-2009, 07:09 AM
alainsi Re: Search and Replace Part... 06-26-2009, 04:53 AM
Richard Schollar Re: Search and Replace Part... 06-26-2009, 05:15 AM
alainsi Re: Search and Replace Part... 06-26-2009, 10:19 AM
Richard Schollar Re: Search and Replace Part... 06-26-2009, 11:34 AM
alainsi Re: Search and Replace Part... 06-29-2009, 04:04 AM
martindwilson Re: Search and Replace Part... 06-29-2009, 08:47 AM
alainsi Re: Search and Replace Part... 06-30-2009, 05:48 AM
  1. #1
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: Search and Replace Part of Formulas

    Alain

    Try this on a copy of your workbook - the sheet where you want the formulas changed should be visible in Excel (ie Active) when you run this. It will only amend formulas with

    LoB1!XX

    in the B column

    Sub change_formulas()
    Dim r As Range
    
    With CreateObject("vbscript.regexp")
        .Global = True
        .Pattern = "(LoB1\!)(($)?[A-Z]{1,2}($)?[0-9]+)"
            For Each r In Application.Intersect(ActiveSheet.Range("B:B"), ActiveSheet.UsedRange).SpecialCells(xlCellTypeFormulas)
                    r.FormulaLocal = .Replace(r.FormulaLocal, "IF(scenario=1;'Lob1'!$2;'LoB2'!$2)")
            Next r
    End With
            
    End Sub
    Richard
    Richard Schollar
    Microsoft MVP - Excel

  2. #2
    Registered User
    Join Date
    06-23-2009
    Location
    Zurich, Switzerland
    MS-Off Ver
    Excel 2002
    Posts
    5

    Thumbs up Re: Search and Replace Part of Formulas

    Richard -

    Problem solved! The solution you found works great - it is also very "flexible" and can easily be adapted to similar problems.

    Thank you very much for your help on this.

    Rgds,
    Alain

+ 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