Find & Replace values in All Sheets except the LookUp Sheet

xlhelp15

Board Regular
Joined
Sep 12, 2014
Messages
113
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
Hello Experts - Would need your kind assistance on the below to change values in all the sheet using VBA.

This is my table in LookUp sheet, would need find the list in Check_ID and replace it with respective File_ID in all sheets.

1666372245884.png



Kindly assist on this.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try this code :

VBA Code:
Sub Find_Replace()
    Dim wb As Workbook, ws As Worksheet
    Dim myList As Variant, myRange As Range
    Dim i As Long, msg As String
    
    ' find/replace list
    Set wb = ThisWorkbook ' or ActiveWorkbook
    myList = wb.Sheets("Sheet1").Range("A1:B238").Value2 'Sheet1 or Sheet Name
   
   
    For Each ws In wb.Sheets
        If ws.Name <> "Sheet1" Then 'Sheet1 or Sheet Name
            Set myRange = ws.Range("A1:AZ9999")
            For i = LBound(myList) To UBound(myList)
                If Len(myList(i, 1)) > 0 Then
                    myRange.Replace _
                      What:=myList(i, 1), _
                      Replacement:=myList(i, 2), _
                      LookAt:=xlWhole
                End If
            Next i
            msg = msg & vbCr & ws.Name
        End If
    Next
    MsgBox "Sheets processed :" & msg, vbInformation, wb.Name
End Sub

Suposing CheckID is column A / File_ID Column B
 
Upvote 0
Solution
Code:
Sub Or_Maybe_So()
Dim rep, i As Long, sh1 As Worksheet, ws As Worksheet
Set sh1 = Worksheets("Sheet1")    '<---- Change as required
rep = sh1.Cells(1, 1).CurrentRegion.Value     '<---- Change as required
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> sh1.Name Then
        With ws.UsedRange
            For i = LBound(rep) + 1 To UBound(rep)
                .Replace rep(i, 1), rep(i, 2), 1
            Next i
        End With
        End If
    Next ws
End Sub
 
Upvote 0
Try this code :

VBA Code:
Sub Find_Replace()
    Dim wb As Workbook, ws As Worksheet
    Dim myList As Variant, myRange As Range
    Dim i As Long, msg As String
   
    ' find/replace list
    Set wb = ThisWorkbook ' or ActiveWorkbook
    myList = wb.Sheets("Sheet1").Range("A1:B238").Value2 'Sheet1 or Sheet Name
  
  
    For Each ws In wb.Sheets
        If ws.Name <> "Sheet1" Then 'Sheet1 or Sheet Name
            Set myRange = ws.Range("A1:AZ9999")
            For i = LBound(myList) To UBound(myList)
                If Len(myList(i, 1)) > 0 Then
                    myRange.Replace _
                      What:=myList(i, 1), _
                      Replacement:=myList(i, 2), _
                      LookAt:=xlWhole
                End If
            Next i
            msg = msg & vbCr & ws.Name
        End If
    Next
    MsgBox "Sheets processed :" & msg, vbInformation, wb.Name
End Sub

Suposing CheckID is column A / File_ID Column B
It worked as a treat !!!! Thanks a lot !
 
Upvote 0
Code:
Sub Or_Maybe_So()
Dim rep, i As Long, sh1 As Worksheet, ws As Worksheet
Set sh1 = Worksheets("Sheet1")    '<---- Change as required
rep = sh1.Cells(1, 1).CurrentRegion.Value     '<---- Change as required
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> sh1.Name Then
        With ws.UsedRange
            For i = LBound(rep) + 1 To UBound(rep)
                .Replace rep(i, 1), rep(i, 2), 1
            Next i
        End With
        End If
    Next ws
End Sub
So easy to understand and worked as expected Thanks much :)
 
Upvote 0
It worked as a treat !!!! Thanks a lot !
Try this code :

VBA Code:
Sub Find_Replace()
    Dim wb As Workbook, ws As Worksheet
    Dim myList As Variant, myRange As Range
    Dim i As Long, msg As String
  
    ' find/replace list
    Set wb = ThisWorkbook ' or ActiveWorkbook
    myList = wb.Sheets("Sheet1").Range("A1:B238").Value2 'Sheet1 or Sheet Name
 
 
    For Each ws In wb.Sheets
        If ws.Name <> "Sheet1" Then 'Sheet1 or Sheet Name
            Set myRange = ws.Range("A1:AZ9999")
            For i = LBound(myList) To UBound(myList)
                If Len(myList(i, 1)) > 0 Then
                    myRange.Replace _
                      What:=myList(i, 1), _
                      Replacement:=myList(i, 2), _
                      LookAt:=xlWhole
                End If
            Next i
            msg = msg & vbCr & ws.Name
        End If
    Next
    MsgBox "Sheets processed :" & msg, vbInformation, wb.Name
End Sub

Suposing CheckID is column A / File_ID Column B
@Flaiban - But landing on another issue - if you look at the Row5 - C253 has 042448. When i run the macro it changes C253 everywhere as 42448 instead of 042448. Is there a way to update the value as it is ?
 
Upvote 0
So easy to understand and worked as expected Thanks much :)
@jolivanes - But landing on another issue - if you look at the Row5 - C253 has 042448. When i run the macro it changes C253 everywhere as 42448 instead of 042448. Is there a way to update the value as it is ?
 
Upvote 0
If the values in Column B end up in the array as displayed, this works.
Change this
Code:
.Replace rep(i, 1), rep(i, 2), 1
to this
Code:
.Replace rep(i, 1), "'" & rep(i, 2), 1
 
Upvote 0

Forum statistics

Threads
1,216,524
Messages
6,131,176
Members
449,629
Latest member
Mjereza

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