+ Reply to Thread
Results 1 to 4 of 4

Find and replace second instance

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-14-2013
    Location
    LA Baby!!
    MS-Off Ver
    Excel 2007
    Posts
    1,598

    Find and replace second instance

    Hello. If there are formulas with 2 number "12's", how can I search and replace the second instance?

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Find and replace second instance

    I believe you need a macro for that.
    Try selecting the cell(s) containing the formula and run this macro.
    Sub SearchAndReplace()
        Dim c As Range, s1, s2, n, j, k
        s1 = "12"   ' Text to search
        s2 = "13"   ' Text to replace with
        n = 2       ' Nth instance to replace
        
        For Each c In Selection
            k = 0
            j = 0
            Do While InStr(j + 1, c.Formula, s1)
                j = InStr(j + 1, c.Formula, s1)
                If j Then k = k + 1
                If k = n Then
                    c.Formula = Left(c.Formula, j - 1) & s2 & Mid(c.Formula, j + Len(s1))
                    Exit Do
                End If
            Loop
        Next
    End Sub
    多么想要告诉你 我好喜欢你

  3. #3
    Forum Contributor
    Join Date
    08-14-2013
    Location
    LA Baby!!
    MS-Off Ver
    Excel 2007
    Posts
    1,598

    Re: Find and replace second instance

    There isn't a way to do it with a formula?

  4. #4
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Find and replace second instance

    Maybe, but I don't know how.

+ 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. Replies: 3
    Last Post: 10-08-2013, 09:46 AM
  2. [SOLVED] Find and Replace first instance of word Only
    By ScabbyDog in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-18-2013, 01:14 PM
  3. [SOLVED] find and replace for instance
    By nicktater in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-11-2013, 04:42 PM
  4. [SOLVED] Lookup Table to Find/Replace Every Instance of a String (2/2)
    By Baghel in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-04-2013, 05:49 AM
  5. Replies: 12
    Last Post: 12-31-2012, 04:13 AM

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