Group values in arrays then replace them with a new value

zack8576

Active Member
Joined
Dec 27, 2021
Messages
271
Office Version
  1. 365
Platform
  1. Windows
I have a large number of excel files to clean up, any of the values contained in these arrays will be replaced by a different value
Below is what I have so far, any help is greatly appreciated

VBA Code:
Sub CleanUpOutlier()
    Array1 = ("1", "2", "3", "4")
    Array2 = ("5", "6", "7", "8")
    With Range("D1", Cells(Rows.Count, "D").End(3))
        .Replace Array1, "F12314J"
        .Replace Array2, "F12315J"
    End With
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
VBA Code:
Sub CleanUpOutlier()
    Dim array1, array2, x
    array1 = Array("1", "2", "3", "4")
    array2 = Array("5", "6", "7", "8")
    With Range("D1", Cells(Rows.Count, "D").End(3))
        For Each x In array1
            .Replace x, "F12314J", xlWhole
        Next
        For Each x In array2
            .Replace x, "F12315J", xlWhole
        Next
    End With
End Sub

Before:

Book3
ABCDE
18
23
33
48
51
63
71
82
97
108
11
Sheet1


After:

Book3
ABCDE
1F12315J
2F12314J
3F12314J
4F12315J
5F12314J
6F12314J
7F12314J
8F12314J
9F12315J
10F12315J
11
Sheet1
 
Upvote 0
Solution

Forum statistics

Threads
1,223,098
Messages
6,170,103
Members
452,302
Latest member
TaMere

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