find and replace unique values on another sheet

pann8888

New Member
Joined
Mar 16, 2012
Messages
13
Hello! I have a spreadsheet that others will use to correct data entries for a unique identifier (i.e., there is only one instance of that text string on a given sheet.) In short, the main spreadsheet imports data from different spreadsheets, and any incorrect unique identifiers must be corrected in the main spreadsheet before other operations can be performed.

I am looking for a VBA-based way to find the Unique Identifier entry from column B, Sheet 1 in Column B, Sheet 8, and replace it with the value in the same row on Sheet 1, Column 6. (Sheet 8 contains sensitive data and is hidden from users). A sample layout of Sheet 1 is below. In my example, ABC123 would be replaced in Sheet 8 Column B with ADB123 (and that would happen with every other unique identifier on Sheet 1, CDE456 being replace in Sheet 8 by CDF457 and so on). As stated above, there is never more than one instance of the unique identifier on either Sheet 1 or Sheet 8. I have used my Google-fu on various posted VBA solutions, but nothing has been close enough to allow my novice-level coding skills to parse a solution. Can someone point me in the right direction, or even suggest a combination of VBA functions to make this happen? Thanks!

Unique Identifier
Name
Email
mismatch?
Enter the corrected Unique Identifier below
ABC123
abc
abc@abc.com
X
ADB123
CDE456
abcd
abc@abc.com
X
CDF457
FGH678
abcde
abc@abc.com
X
FGH677
IJK9111
abcded
abc@abc.com
X
IJL1111

<tbody>
</tbody>
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I figured this out, thanks to a 2016 post by Joe4.

Sub myReplace()
Dim myDataSheet As Worksheet
Dim myReplaceSheet As Worksheet
Dim myLastRow As Long
Dim myRow As Long
Dim myFind As String
Dim myReplace As String

' Specify name of Data sheet
Set myDataSheet = Sheets("whatever")

' Specify name of Sheet with list of replacements
Set myReplaceSheet = Sheets("whatever2")

myLastRow = 141

Application.ScreenUpdating = False

' Loop through all list of replacements
For myRow = 22 To myLastRow

' Get find and replace values (from columns A and B)
myFind = myReplaceSheet.Cells(myRow, "B")
myReplace = myReplaceSheet.Cells(myRow, "G")
' Start at top of data sheet and do replacements
myDataSheet.Activate
Range("B5").Select
' Ignore errors that result from finding no matches
On Error Resume Next
' Do all replacements on column B of data sheet
If myReplace <> "" Then
Columns("B:B").Replace What:=myFind, Replacement:=myReplace, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
' Reset error checking
On Error GoTo 0
End If
Next myRow

Application.ScreenUpdating = True

MsgBox "Replacements complete!"

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,147
Messages
6,123,297
Members
449,095
Latest member
Chestertim

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