VBA to replace cell value

delice

New Member
Joined
Aug 13, 2023
Messages
1
Office Version
  1. 2021
Platform
  1. Windows
Hi, Im Pablo, I have a Workbook named "recepies", and this workbook has 90 sheets and all with diferent names: "cost", "sales", "cheescake", "math", "key lime pie", "red velvet", etc...
sometimes I need to replace text in several sheets (not all of them) just a selection (like 80 sheets) and if I use the excel opcion find/replace text or numbers, the value is Replace in all sheets or only in the sheet im working. Im looking for a VBA code to do this:
 
Last edited by a moderator:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Hi, Im Pablo, I have a Workbook named "recepies", and this workbook has 90 sheets and all with diferent names: "cost", "sales", "cheescake", "math", "key lime pie", "red velvet", etc...
sometimes I need to replace text in several sheets (not all of them) just a selection (like 80 sheets) and if I use the excel opcion find/replace text or numbers, the value is Replace in all sheets or only in the sheet im working. Im looking for a VBA code to do this:
Hi Pablo

Welcome to Mr Excel.

Do you have the list of worksheets that you want to replace data in or the list of worksheets that you don't want to replace data in?

Does the value to find and replace with come from the values in two cells?

Do you want to replace partial cell values or whole cell values?
 
Upvote 0
Hi, Im Pablo, I have a Workbook named "recepies", and this workbook has 90 sheets and all with diferent names: "cost", "sales", "cheescake", "math", "key lime pie", "red velvet", etc...
sometimes I need to replace text in several sheets (not all of them) just a selection (like 80 sheets) and if I use the excel opcion find/replace text or numbers, the value is Replace in all sheets or only in the sheet im working. Im looking for a VBA code to do this:
Am I to understand that you are looking for something like the Find and Replace function of Excel but you would like to be able to choose if it looks in the whole Workbook or only selected Worksheets?
 
Upvote 0
Hi, Im Pablo, I have a Workbook named "recepies", and this workbook has 90 sheets and all with diferent names: "cost", "sales", "cheescake", "math", "key lime pie", "red velvet", etc...
sometimes I need to replace text in several sheets (not all of them) just a selection (like 80 sheets) and if I use the excel opcion find/replace text or numbers, the value is Replace in all sheets or only in the sheet im working. Im looking for a VBA code to do this:

This suggestion uses a worksheet named 'Master'. You can change this.


VBA Code:
Public Sub subLoopThroughWorksheets()
Dim rngWorksheets As Range
Dim rng As Range

    ' Replace 'Master' with the name of your sheet.
    
    ActiveWorkbook.Save
    
    ' This range contains the list of worksheets to replace data in.
    Set rngWorksheets = Worksheets("Master").Range("A2:A7")

    ' Cell Master B2 contains the value to look for.
    ' Cell Master B3 contains the value to replace.
    For Each rng In rngWorksheets.Cells
        Worksheets(rng.Value).Cells.Replace what:=Worksheets("Master").Range("B2"), _
            Replacement:=Worksheets("Master").Range("B3"), LookAt:=xlWhole, MatchCase:=True
    Next rng
    
End Sub

Find And Replace.xlsm
AB
1Worksheet
2CostBinder
3SalesPen
4Cheesecake
5Math
6Key Lime Pie
7Red Velvet
Master
 
Upvote 0

Forum statistics

Threads
1,215,093
Messages
6,123,067
Members
449,090
Latest member
fragment

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top