+ Reply to Thread
Results 1 to 5 of 5

Search & Replace

  1. #1
    Forum Contributor
    Join Date
    10-13-2011
    Location
    Australia
    MS-Off Ver
    Office 16
    Posts
    329

    Search & Replace

    I have the following macro but I need it to replace contents of a variable cell, then paste it into the replace field, it's almost a paste special however this isn't an option that I know of in search and replace. Can anyone fix this for me?

    What I want is - copy contents of a cell in row 2 (e.g. B2), then select the entire row B, search for '01 New Client', and replace by a paste command (the contents of cell B2 - which is part of an IF( formula ). The cell reference of B2 for the initial copy is variable, as I want to use the same macro function another rows i.e. cell B3 to copy, search & replace into row 3, then 4, then 5 etc. See problem sheet attached - If formula is in Row D.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Christopherdj; 10-26-2011 at 06:50 PM. Reason: missing code tags

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Search & Replace

    I'm just trying to get to grips with what you're trying to do here.

    Is the purpose of this macro to update the sheet reference in your formula when you add a new client?

    If so then you can do it just with formula, there's no need to use a macro.

    Replacing the formula in D3 of the problem sheet with =IF(ISERROR(INDIRECT("'"&B3&"'!A1")),"",IF(COUNTIF(INDIRECT("'"&B3&"'!E88:E100"),"Yes")>0,"Yes","")) should do the job.

  3. #3
    Forum Contributor
    Join Date
    10-13-2011
    Location
    Australia
    MS-Off Ver
    Office 16
    Posts
    329

    Re: Search & Replace

    I'm not sure of your reply and its use, but yes I am trying to update the formula every time I add a new client. This is one of many sheets with different forumula's but all are based on a '01 new client' sheet reference that needs amending for each new client.

    The macro I created works fine for the first client, however it doesn't allow for any subsequent client using search and replace. With the formula provided below, if the replacement:="SMITH, Robert" and "Jones, John" were a PASTE option/instruction, it would work fine. Is there a function to replace it?? like .PASTE (I tried this and it doesn't work).
    {CODE}
    Sub Formula_Replace()
    '
    ' Formula_Replace Macro
    '

    '
    Selection.Copy
    ActiveCell.Rows("1:1").EntireRow.Select
    ActiveCell.Offset(0, 2).Range("A1").Activate
    Selection.Replace What:="01 new client", Replacement:="SMITH, Robert" _
    , LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat _
    :=False, ReplaceFormat:=False
    ActiveCell.Offset(1, -2).Range("A1").Select
    Application.CutCopyMode = False
    Selection.Copy
    ActiveCell.Rows("1:1").EntireRow.Select
    ActiveCell.Activate
    Selection.Replace What:="01 new client", Replacement:="Jones, John", _
    LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:= _
    False, ReplaceFormat:=False
    End Sub
    {CODE}

  4. #4
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Search & Replace

    Your code tags need square brackets, not curly ones.

    Did you try putting the formula I gave you into cell D3? It does exactly what you're trying to do with your macro, but it's much more straightforward.

  5. #5
    Forum Contributor
    Join Date
    10-13-2011
    Location
    Australia
    MS-Off Ver
    Office 16
    Posts
    329

    Re: Search & Replace

    OMG, I pasted into the wrong cell. It works..... thank you very much - Problem solved. This will save me heaps of time.

+ 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