Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to find and replace multiple values at once in Excel?

doc multiple find replace 1

As we all known, we can use Find and Replace function to find multiple same cell and replace them with a value as you need. But sometimes, you need to apply many-to-many replacement simultaneously. For example, I have a range of data, and now I want to replace all Apples to Red Apples, Oranges to Green Oranges, Bananas to Yellow Bananas and so on as following screenshots shown, do you have any good ideas to solve this task in Excel?

Find and replace multiple values at once with VBA code


Find and replace in opened workbooks or multiple worksheets:

Kutools for Excel’s Find and Replace feature can help you to find and replace the values from opened workbooks or specific worksheets you need.

doc-multiple-find-and-replace-6

arrow blue right bubble Find and replace multiple values at once with VBA code


If you are tired of find and replace the values time and time again, the following VBA code can help you to replace multiple values with your needed texts at once.

1. Please create your conditions that you want to use which contain the original values and new values. See screenshot:

doc multiple find replace 2

2. Then hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

3. Click Insert > Module, and paste the following code in the Module window.

VBA code: Find and replace multiple values at once

Sub MultiFindNReplace()
'Update 20140722
Dim Rng As Range
Dim InputRng As Range, ReplaceRng As Range
xTitleId = "KutoolsforExcel"
Set InputRng = Application.Selection
Set InputRng = Application.InputBox("Original Range ", xTitleId, InputRng.Address, Type:=8)
Set ReplaceRng = Application.InputBox("Replace Range :", xTitleId, Type:=8)
Application.ScreenUpdating = False
For Each Rng In ReplaceRng.Columns(1).Cells
    InputRng.Replace what:=Rng.Value, replacement:=Rng.Offset(0, 1).Value
Next
Application.ScreenUpdating = True
End Sub

4. Then press F5 key to run this code, in the popped out prompt box, please specify the data range that you want to be replaced the values with new values.

doc multiple find replace 3

5. Click OK, and another prompt box is displayed to remind you select the criteria which you are created in step 1. See screenshot:

doc multiple find replace 4

6. Then click OK, all the specific values have been replaced with the new values as you need immediately.

doc multiple find replace 5


Related articles:

How to find and replace specific text in text boxes?

How to find and replace text in chart titles in Excel?

How to find and replace text within comments in Excel?

How to change multiple hyperlink paths at once in Excel?


Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    A Davies · 3 days ago
    Absolute hero! Thanks!
  • To post as a guest, your comment is unpublished.
    vikram · 18 days ago
    Thanks a ton.
  • To post as a guest, your comment is unpublished.
    Lord Balish · 1 months ago
    Hi!
    i need this macro to work on specific columns without selecting different columns each time manually.
    is there any way to mention desired columns and replacing table in the code?
    appreciated
  • To post as a guest, your comment is unpublished.
    Mert · 2 months ago
    what should i change to make the replacing range FIXED, i dont want to re-enter every time?
  • To post as a guest, your comment is unpublished.
    fan of this article · 3 months ago
    Thanks a lot, that works perfectly !
  • To post as a guest, your comment is unpublished.
    spoorthi · 3 months ago
    Thank YOU So much , it works like a magic ...saves my time.. thanks a ton :)
  • To post as a guest, your comment is unpublished.
    Tanay · 4 months ago
    Hello. Thank you for the help. But it is not renaming the entire cell if it is a large string. For any cell which has more than 21 letters, it can only replace 21 letters and then else is same. Please help.
  • To post as a guest, your comment is unpublished.
    MURUGAN T G · 5 months ago
    Hi im TG,Thank you for posting this page, It's very useful and make it very simple of my work and save more time , thank you sir....
  • To post as a guest, your comment is unpublished.
    Jairo L. · 7 months ago
    Muchas Gracias me fue de mucha utilidad el codigo.
  • To post as a guest, your comment is unpublished.
    iris · 8 months ago
    it works! THANK YOU SO MUCH!
  • To post as a guest, your comment is unpublished.
    Jon · 10 months ago
    Макрос не работает корректно !!! Пытался подобным образом заменить символы, но не различаются маленькие и большие буквы.
  • To post as a guest, your comment is unpublished.
    Ugnė Vitkutė · 1 years ago
    Hi, I would like to replace whole cells in the entire Excel file (with many sheets). What should be replace in the Original Range to do that? Thanks.
  • To post as a guest, your comment is unpublished.
    Ugne · 1 years ago
    What should be replaced in the code to run it on all the Excel file's sheets?
  • To post as a guest, your comment is unpublished.
    Tina Sun · 1 years ago
    Can I ask if I want to replace the entire cell based on partial match, how should I alter the code?
    For example: I want to code all cells containing the word apple to 1 (regardless whether it's "green apple" or "red apple"), I want all of them to turn into 1.
  • To post as a guest, your comment is unpublished.
    Carlos · 1 years ago
    El mejor!!! Mil gracias por compartir estos conocimientos, fue increíble la ayuda que me proporciono este programa en VBasic (nunca lo había usado hasta ahora), lo pensaba realizar en php o similar pero leyendo encontre esta valiosa información.

    Gracias!
  • To post as a guest, your comment is unpublished.
    Abhishek · 1 years ago
    The VBA method of find and replace is not working. It was working for me till yesterday but today I am not able to do any find and replace using it today. Can you guys please help
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hi, Abhishek,
      After inserting the code into the workbook, you should save the workbook as Excel Macro-Enabled Workbook format to keep the code without losing it.
      Please try it, hope this can help you!
  • To post as a guest, your comment is unpublished.
    Am · 1 years ago
    This is causing my original values data to also be replaced, in addition to the column of data I want to be replaced. How do I stop this?
  • To post as a guest, your comment is unpublished.
    Joe · 1 years ago
    Thanks, this worked perfectly.
  • To post as a guest, your comment is unpublished.
    mohan · 1 years ago
    Hi

    I have to replace list of bank with proper name based on key words. For example, if somebody enters Halifax, it should be Halifax Bank of Scotland (HBOS) or if somebody enters LloydsTSB, it should be Lloyds.

    Original value Replacing Value
    LloydsTSB : Lloyds
    Santander : Santander (Abbey)
    Argos Card Services : Argos
    Halifax : Halifax Bank of Scotland (HBOS)

    The down formula works in many cases. But if there is two Halifax bank on my list, I will get Halifax Bank of Scotland (HBOS) (HBOS)
    . So, first time it finds Halifax, replace with correct one. Again it finds Halifax and replace. How can I correct this problem ?


    Sub FindReplaceNew()
    Dim xTitledId As String
    Dim Rng As Range
    Dim InputRng As Range, ReplaceRng As Range
    xTitledId = "Test"
    Set InputRng = Application.Selection
    Set InputRng = Application.InputBox("Original Range", xTitledId, InputRng.Address, Type:=8)
    Set ReplaceRng = Application.InputBox("Replace Range :", xTitledId, Type:=8)
    Application.ScreenUpdating = False

    For Each Rng In ReplaceRng.Columns(1).Cells
    InputRng.Replace what:=Rng.Value, replacement:=Rng.Offset(0, 1).Value
    Next
    Application.ScreenUpdating = False


    End Sub
  • To post as a guest, your comment is unpublished.
    David Gaertner · 1 years ago
    I modified this to work on Microsoft Excel for Mac 2016 and to replace strings that are within whole words. Here are the first and last lines I changed (along with the stuff in between that I didn't change).
    Set InputRng = Application.InputBox(Prompt:="Original Range :", Title:="Range to search", Default:=InputRng.Address, Type:=8)
    Set ReplaceRng = Application.InputBox(Prompt:="Replace Range :", Title:="Replace mapping range", Type:=8)
    Application.ScreenUpdating = False
    For Each Rng In ReplaceRng.Columns(1).Cells
    InputRng.Replace what:=Rng.Value, replacement:=Rng.Offset(0, 1).Value, LookAt:=xlPart
  • To post as a guest, your comment is unpublished.
    Etienne · 1 years ago
    Hello, how can I only replace full words (and not strings within a word) ? By word, I mean a string that is at the beginning/end of the cell or preceded/followed with a space.
    • To post as a guest, your comment is unpublished.
      Khamir · 1 years ago
      Use this code.


      Sub MultiFindNReplace()
      Dim Rng As Range
      Dim InputRng As Range, ReplaceRng As Range
      xTitleId = "MultipleReplaceValue"
      Set InputRng = Application.Selection
      Set InputRng = Application.InputBox("Original Range ", xTitleId, InputRng.Address, Type:=8)
      Set ReplaceRng = Application.InputBox("Replace Range :", xTitleId, Type:=8)
      Application.ScreenUpdating = False
      For Each Rng In ReplaceRng.Columns(1).Cells
      InputRng.Replace what:=Rng.Value, replacement:=Rng.Offset(0, 1).Value, LookAt:=xlWhole, MatchCase:=True
      Next
      Application.ScreenUpdating = True
      End Sub
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hello, Etienne,
      Can you give an example screenshot for your problem?
      Thank you!
  • To post as a guest, your comment is unpublished.
    Etienne · 1 years ago
    Hello, how can I replace only full words. Replace only if the string is at the beginning/end of the cell or preceded/followed by a space ?
  • To post as a guest, your comment is unpublished.
    pratik · 1 years ago
    Sub MultiFindNReplace()

    'Update 20140722

    Dim Rng As Range

    Dim InputRng As Range, ReplaceRng As Range

    xTitleId = "KutoolsforExcel"

    Set InputRng = Application.Selection

    Set InputRng = Application.InputBox("Original Range
    ", xTitleId, InputRng.Address, Type:=8)

    Set ReplaceRng = Application.InputBox("Replace Range
    :", xTitleId, Type:=8)

    Application.ScreenUpdating = False

    For Each Rng In ReplaceRng.Columns(1).Cells

    ' InputRng.Replace what:=Rng.Value,
    replacement:=Rng.Offset(0, 1).Value

    InputRng.Replace
    Rng.Value, Rng.Offset(0, 1).Value

    Next

    MsgBox "Done Successfully....", vbInformation

    Application.ScreenUpdating = True

    End Sub
  • To post as a guest, your comment is unpublished.
    ramanuj sharma · 1 years ago
    THANKS A LOT.....
    ITS MOST EFFECTIVE CODE TO USE....


    THANKS SIR,
  • To post as a guest, your comment is unpublished.
    francesco · 1 years ago
    how do I implement "match entire cell content" in this code?
    • To post as a guest, your comment is unpublished.
      Boris Chevreau · 1 years ago
      in case someone else is looking for this, here it is:

      Replace this line
      InputRng.Replace what:=Rng.Value, replacement:=Rng.Offset(0, 1).Value

      by
      InputRng.Replace what:=Rng.Value, replacement:=Rng.Offset(0, 1).Value, LookAt:=xlWhole



      It will look for the whole cell in target and original, and replace by a whole cell instead of particular instances of doubles inside a cell
  • To post as a guest, your comment is unpublished.
    Jorge Vargas · 2 years ago
    don't work in all the columns for me idk why
  • To post as a guest, your comment is unpublished.
    Hans Filbert · 2 years ago
    Perfect Solution.
    Easy to use.
  • To post as a guest, your comment is unpublished.
    Kalle · 2 years ago
    Hi, this was very powerful and useful code. Thanks a lot! There is just a couple of features lacking and it would be perfect for me: 1) Could it be possible to modify the code so that it would process multiple files at once? For example you have your find_replace attributes in different file and then you just name the files in the VBA code you want to modify. I dunno...That would be cool. 2) Could it be possible to make a report so that I would know what attributes were replaced. So that I could double-check if something went wrong.
  • To post as a guest, your comment is unpublished.
    Roshan · 2 years ago
    this is very useful .. Thanks You!!
  • To post as a guest, your comment is unpublished.
    dSd · 2 years ago
    Excellent work!!!!!
    This saved me after my enterprise free period got over!
  • To post as a guest, your comment is unpublished.
    karel · 2 years ago
    wohoo, made my day. thank you
  • To post as a guest, your comment is unpublished.
    styleguerilla · 2 years ago
    How can I make this VBA macro work for a formula, e.g. if I want to replace 'Sheet1!$A:$A' with Table1[A]?
  • To post as a guest, your comment is unpublished.
    Jason Ebensberger · 2 years ago
    This is AWESOME!!! Very simple solution to my problem. THANK YOU!
  • To post as a guest, your comment is unpublished.
    sohberson · 2 years ago
    in case anybody still struggles with replacing entire cell value and not just part: use Lookat:=xlWhole

    Sub MultiFindNReplace()
    'Update 20140722
    Dim Rng As Range
    Dim InputRng As Range, ReplaceRng As Range
    xTitleId = "KutoolsforExcel"
    Set InputRng = Application.Selection
    Set InputRng = Application.InputBox("Original Range ", xTitleId, InputRng.Address, Type:=8)
    Set ReplaceRng = Application.InputBox("Replace Range :", xTitleId, Type:=8)
    Application.ScreenUpdating = False
    For Each Rng In ReplaceRng.Columns(1).Cells
    InputRng.Replace what:=Rng.Value , replacement:=Rn g.Offset(0, 1).Value, Lookat:=xlWhole
    Next
    Application.ScreenUpdating = True
    End Sub
    • To post as a guest, your comment is unpublished.
      JProf · 2 years ago
      Was looking for this specifically - thank you!
  • To post as a guest, your comment is unpublished.
    Nathan Rona · 2 years ago
    thanks, you're great. Your script saved me at least half an hour of find and replace :lol:
  • To post as a guest, your comment is unpublished.
    Avril · 2 years ago
    This tutorial was excellent! Did what I needed it to do.

    Is there a way to automatically run this macro on specific columns every time I open it/after pressing a key or something easy? After I've already saved the macro on a macro enabled file. I am creating a document to share with my colleagues and I'm not sure everyone will follow all the steps.

    Thank you!
  • To post as a guest, your comment is unpublished.
    Jin · 2 years ago
    xxx 1
    xxx 2
    xxx 3
    xxx 4
    xxx 5
    xxx 6

    Sir, how can i replace 1, 2, 3, 4, 5, 6 into xxx in a very short period of time?
  • To post as a guest, your comment is unpublished.
    David · 2 years ago
    This VBA script just saved me hours if not days of find and replace data entry. Thanks for sharing :)
  • To post as a guest, your comment is unpublished.
    Christopher Witmer · 2 years ago
    This saved me hours of work. Thank you soooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo much.
  • To post as a guest, your comment is unpublished.
    Jeremiah H · 2 years ago
    I LOVE this formula and use it all the time!

    I need a very similar formula but can't work out the logic.

    Column A is full cells with lots of text.

    Column B is full of my 'keywords' that I want to extract, much like the 'Original Value' in this formula.

    Column C needs to be the words from Column A that match the 'keywords' in Column B. Ideally they would be separated by commas with NO spaces, but I can use tools to insert these.

    Thanks, guys, your stuff is amazing!
  • To post as a guest, your comment is unpublished.
    Siddharth Gadia · 2 years ago
    How to do it for Exact Cell match?? if not exact, it should leave it.
  • To post as a guest, your comment is unpublished.
    Michael · 2 years ago
    Hie guys, I have used the Macro Below and it worked perfectly, however I am now having challenges with filtered values, is it possible to make the effect of the macro only on the filtered data.

    Sub MultiFindNReplace()
    'Update 20140722
    Dim Rng As Range
    Dim InputRng As Range, ReplaceRng As Range
    xTitleId = "KutoolsforExcel"
    Set InputRng = Application.Selection
    Set InputRng = Application.InputBox("Original Range ", xTitleId, InputRng.Address, Type:=8)
    Set ReplaceRng = Application.InputBox("Replace Range :", xTitleId, Type:=8)
    Application.ScreenUpdating = False
    For Each Rng In ReplaceRng.Columns(1).Cells
    InputRng.Replace what:=Rng.Value, replacement:=Rng.Offset(0, 1).Value
    Next
    Application.ScreenUpdating = True
    End Sub

    Please help urgently, my boss is on my neck.
  • To post as a guest, your comment is unpublished.
    Patrick Miller · 2 years ago
    So I'm trying to do a replacement range as seen below.

    Original Value Replacing range.
    0 to 1 1
    0 to 2 1,2
    0 to 99 1,2,3,4,5,6,7,8,9,10,11,12,13
    13 to 99 13

    However anything with 99 in it gives me a funky number and doesn't replace properly. I don't know what to do. Something broke as of recently Because this script was working fine last week. Now it's all broken. I'm getting replacement like 14,5,6,7,8,9,109, for the value 13 to 99. And for the value 8 to 99 it's replacing it with 19109. I'm at a complete loss here. Help!
  • To post as a guest, your comment is unpublished.
    Patrick Miller · 2 years ago
    So I'm trying to use this script to a replacement with age ranges. To a code listing. But it's not inputting correctly.

    Original Value Replacing Value
    0 to 1 1
    0 to 2 1,2
    0 to 3 1,2,3
    0 to 4 1,2,3,4
    0 to 5 1,2,3,4,5
    0 to 6 1,2,3,4,5,6
    0 to 7 1,2,3,4,5,6,7
    0 to 8 1,2,3,4,5,6,7,8
    0 to 9 1,2,3,4,5,6,7,8,9
    0 to 10 1,2,3,4,5,6,7,8,9,10
    0 to 11 1,2,3,4,5,6,7,8,9,10,11
    0 to 12 1,2,3,4,5,6,7,8,9,10,11,12
    0 to 13 1,2,3,4,5,6,7,8,9,10,11,12,13
    13 to 99 13

    As you see above this is how the replacing ranges should look. But for numbers like 13 to 99 it gets replaced with like 14,15,16,109 instead of of having the replacement be 13. I don't know what is causing this. Last week this script was working fine but now it broke.
  • To post as a guest, your comment is unpublished.
    Nirosni Srikantharaj · 2 years ago
    Hi:

    I need to replace a formula (=F108+Start!I108) with (=F108+'Jan 17'!I108) throughout the sheet. I am not able to just find and replace since there is only one cell with that formula. Each cell has its own number... Can you help to to find the replace the Start with Jan 17. Thank you.
  • To post as a guest, your comment is unpublished.
    Qudsia · 3 years ago
    This is very useful article, its works perfect for me. Thanks a lot
  • To post as a guest, your comment is unpublished.
    anubhav mehra · 3 years ago
    how to change 32642/319/09-07-08 only change 32642-319/09-07-08 this format all sheet only change first / to - not change all
  • To post as a guest, your comment is unpublished.
    Chris · 3 years ago
    Your module worked perfectly and has saved me many hours ( Thank You )

    Is it possible to find and ''highlight'' fill red for example multiple values at once in Excel
  • To post as a guest, your comment is unpublished.
    Mohanraj · 3 years ago
    Thanks a lot, this macro really helped me to complete the work in lightning speed.
  • To post as a guest, your comment is unpublished.
    Rhonda · 3 years ago
    I am using your code mostly successfully, except I need to match case. My value table is a list of Acronyms, and the Replacement Range is a list of Item Descriptions. I am replacing all acronyms in the items descriptions with the match text; ie, HDD = High Definition Digital, or DVD = Digital Video Disc. But when the code attempts to replace PROX with Proximity, and there's already the word Proximity in the item description, I get Proximityimity. How do I match the CASE?