+ Reply to Thread
Results 1 to 7 of 7

Macro to Find and Replace Multiple Values Across Multiple Sheets

Hybrid View

MattyD123 Macro to Find and Replace... 10-19-2018, 01:44 AM
aarona Re: Macro to Find and Replace... 10-19-2018, 02:45 AM
jindon Re: Macro to Find and Replace... 10-19-2018, 02:54 AM
MattyD123 Re: Macro to Find and Replace... 10-19-2018, 05:25 PM
jindon Re: Macro to Find and Replace... 10-19-2018, 06:59 PM
dtsioustas Re: Macro to Find and Replace... 12-09-2018, 12:55 PM
jindon Re: Macro to Find and Replace... 12-09-2018, 10:44 PM
  1. #1
    Registered User
    Join Date
    10-19-2018
    Location
    DC
    MS-Off Ver
    2016
    Posts
    2

    Macro to Find and Replace Multiple Values Across Multiple Sheets

    Hi all,

    I'm trying to write a macro to find and replace three different values and replace them with one value across a few of the sheets in my workbook, but not having much luck. Any chance somebody could help steer me in the right direction to do something like this? I'm pretty new to VBA overall, so my apologies if this is very off

    Sub FindRep()
    
    Dim e
        For each e In Array(Array("Ahead", "Cancelled"), Array("On time", "Cancelled"), Array("Behind", "Cancelled"))
        Sheets(Array("Jan", "Feb", "March", "April")).Range.Replace e(0), e(1), 1
    Next
    End Sub
    Thanks for any help you can offer here!
    Last edited by MattyD123; 10-22-2018 at 08:31 PM. Reason: Solved

  2. #2
    Forum Contributor
    Join Date
    06-07-2016
    Location
    Manila
    MS-Off Ver
    365
    Posts
    292

    Re: Macro to Find and Replace Multiple Values Across Multiple Sheets

    hi this will do:

    just replace the find and replace strings:

    Sub findreplace()
    
    Dim ws As Worksheet
    Dim fList As Variant
    Dim replacelist As Variant
    Dim aa As Long
    
    
    fList = Array("Find1", "Find2", "Find3", "Find4")
    replacelist = Array("Replace1", "Replace2", "Replace3", "Replace4")
    
      For aa = LBound(fList) To UBound(fList)
          For Each ws In ActiveWorkbook.Worksheets
            ws.Cells.Replace What:=fList(aa), Replacement:=replacelist(aa), _
              LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
              SearchFormat:=False, ReplaceFormat:=False
          Next ws
      
      Next aa
    
    End Sub
    or, you can use input box:

    Sub test()
    
    Dim ws As Worksheet
    Dim fList As Variant
    Dim replacelist As Variant
    Dim aa As Long
    
    Dim mfile As Variant
    Dim replaceS As Variant
    
    mfile = InputBox("Place find text")
    
    replaceS = InputBox("Place replace text")
    
    
    fList = Array(mfile)
    replacelist = Array(replaceS)
    
      For aa = LBound(fList) To UBound(fList)
          For Each ws In ActiveWorkbook.Worksheets
            ws.Cells.Replace What:=fList(aa), Replacement:=replacelist(aa), _
              LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
              SearchFormat:=False, ReplaceFormat:=False
          Next ws
      
      Next aa
    
    
    End Sub

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Macro to Find and Replace Multiple Values Across Multiple Sheets

    Perhaps
    Sub FindRep()
        Dim e, ws As Worksheet
        For Each ws In Sheets(Array("Jan", "Feb", "March", "April"))
            For Each e In Array("Ahead", "On time", "Behind")
                ws.Cells.Replace e, "Cancelled", 1
            Next
        Next
    End Sub

  4. #4
    Registered User
    Join Date
    10-19-2018
    Location
    DC
    MS-Off Ver
    2016
    Posts
    2

    Re: Macro to Find and Replace Multiple Values Across Multiple Sheets

    Thanks, jindon! This is along the lines of what I'm looking for and works across all sheets. The one issue is that this only works if it matches the cell contents exactly. Ideally, I'd like it to replace the string within the cell (e.g. cell goes from "January, 2.1 - Ahead" to "January, 2.1 - Cancelled"), and within formulas. I realize I should have clarified this in my original post.

    Thanks for the help!
    Last edited by MattyD123; 10-19-2018 at 05:32 PM.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Macro to Find and Replace Multiple Values Across Multiple Sheets

    Then you can just change last parameter of Replace method 1 to 2.

  6. #6
    Registered User
    Join Date
    08-02-2011
    Location
    Greece
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Macro to Find and Replace Multiple Values Across Multiple Sheets

    how the word "Cancelled" be red;
    Thank you

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Macro to Find and Replace Multiple Values Across Multiple Sheets

    I don't understand what you are trying to do now.

    If you upload a workbook with before/after, it will help.

    Attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

+ 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. Macro to Find & Replace Font formats for Multiple Values
    By GemBox in forum Word Formatting & General
    Replies: 6
    Last Post: 03-12-2018, 02:01 PM
  2. Find and Replace across Multiple Sheets
    By adambriggs in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 12-31-2014, 10:28 AM
  3. [SOLVED] Find & Replace Matching Cells Across Multiple Sheets
    By texmexcel in forum Excel General
    Replies: 5
    Last Post: 12-15-2013, 05:25 AM
  4. Multiple find and replace for multiple sheets
    By geedaigo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-25-2013, 03:05 PM
  5. find and replace multiple values across multiple worksheets
    By Blake 7 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-13-2012, 10:48 AM
  6. Find and Replace in multiple sheets
    By Josh_123456 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-11-2011, 05:29 PM
  7. Find and Replace in multiple sheets
    By Excel Newbie05 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-06-2008, 04:34 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