Find value in separate range and replace

SAE01

New Member
Joined
Oct 6, 2015
Messages
7
Sheet1, column A contains the following data:

BOFL
BOF Locations
Building our Future Locations

These are all variations of the same same value, just written in slightly different ways.

In Sheet 2, Column A, I have listed all of the variations (I may need to add more variations in future). I want the macro to run though each cell in Sheet1, ColumnA. If the cell value matches one of the variations in the list on Sheet 2, Column A, replace the Sheet 1 value with "BOFL".

This comes with the added complication that the list in sheet 1 then goes onto another set of variations:

CFtF
Compliance for the future
Compliance FtF

The standard return for these should be "CFTF", and the list of variations are held in Sheet 2, Column B. So i'd like to code to move on to standardising these.

My second point is that I'm not sure if holding a list of variations on sheet 2 is the most efficient way to do this. Can the variations been written into the code, and new ones simply added to the code as they're uncovered?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
How about
Code:
Sub StandardiseData()

   Dim Ary1 As Variant
   Dim Ary2 As Variant
   Dim Cl As Range
   
   Ary1 = Array("BOF Locations", "Building our Future Locations")
   Ary2 = Array("Compliance for the future", "Compliance FtF")
   
   For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
      If UBound(Filter(Ary1, Cl.Value, True, vbTextCompare)) >= 0 Then
         Cl.Value = "BOFL"
      ElseIf UBound(Filter(Ary2, Cl.Value, True, vbTextCompare)) >= 0 Then
         Cl.Value = "CFTF"
      End If
   Next Cl
   
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,307
Members
452,633
Latest member
DougMo

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