I would like to know how to run a vba script to find and replace multiple words in only one sheet not the whole workgroup?

Miguel Reyes

I have found a vba script to find and replace words but the script replaces the words in the whole workbook, I would like it to replace the words only in a specific sheet. This is the code I have found.

Sub Multi_FindReplace()
'PURPOSE: Find & Replace a list of text/values throughout entire workbook
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault

Dim sht As Worksheet
Dim fndList As Variant
Dim rplcList As Variant
Dim x As Long

fndList = Array("United States", "New York")
rplcList = Array("US", "NY")

'Loop through each item in Array lists
  For x = LBound(fndList) To UBound(fndList)
    'Loop through each worksheet in ActiveWorkbook
      For Each sht In ActiveWorkbook.Worksheets
        sht.Cells.Replace what:=fndList(x), Replacement:=rplcList(x), _
          LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
          SearchFormat:=False, ReplaceFormat:=False
      Next sht

  Next x

End Sub
SJR

Just remove the sheet loop and specify the sheet name in the code where it says "Sheet1".

Sub Multi_FindReplace()

Dim sht As Worksheet
Dim fndList As Variant
Dim rplcList As Variant
Dim x As Long

fndList = Array("United States", "New York")
rplcList = Array("US", "NY")
Set sht = ActiveWorkbook.Worksheets("Sheet1")   'this is the relevant worksheet    
For x = LBound(fndList) To UBound(fndList)
   sht.Cells.Replace what:=fndList(x), Replacement:=rplcList(x), _
        LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
        SearchFormat:=False, ReplaceFormat:=False
Next x

End Sub

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I find and replace 'whole words only', in Microsoft Word?

I would like only one application to run

Replace multiple words with only one word in googlesheets with apps script

How can I assign a Google Sheet script to only one sheet?

I would like to run a command as a bash script?

how to run my selenium script on multiple servers at the same time so that i would saved one by one execution time?

How do I apply script to only one sheet

Indesign GREP - How to find multiple words but change only one

How can I find & replace a single word to multiple different words?

How to subtract and divide the values in bash script and also i would like to know in the form of percent

Replace multiple words in Excel sheet

Google app script OnEdit to run only on one cell in one sheet

How to loop through a column on one sheet and find value and replace with value on another in vba

How to use LIKE in a query to find multiple words?

If I have multiple datagridviews on one form, how would I allow a row selection to be active on only one at a time?

I would like to run terraform only for a specific resource

How to search and replace for multiple words in one shot

I would like to know how to sort just letters that are in a function

I would like to know how to retrieve index information in Oracle

I would like to know how this code can be rewritten as an IF statement?

I would like to know how to access control with GAE

Python i would like to know how to writerow with a for loop (DictWriter)

I would like to know how to calculate the percentage of a color in an image

I would like to know how to use $$eval from Puppeteer

I would like to know how to map dictionary with list of value to dataframe

I would like to know how to select all files with selenium python

I would like to know how to style bs5-lightbox

I would like to know how to create a slider to change the text size

How I replace multiple chars with only one char in a simple way?