Question

I have a list of hundreds of companies in a column. There are repeat companies that were inputted differently. (i.e. "Nike" vs "Nike Inc")

I am trying to program a macro in excel to loop through the column to search for "Nike" and if found it will replace what is in that cell to a consistent company name (i.e. "Nike, Inc.") The goal would be to have the macro search for many companies.

I appreciate any help!

Was it helpful?

Solution

Here is an example for Nike and Ford

Sub Company()
    ary = Array("Nike", "Ford")
    Dim v As String, i As Long, j As Long
    For i = LBound(ary) To UBound(ary)
        v = ary(i)
        For j = 1 To Cells(Rows.Count, "A").End(xlUp).Row
            If InStr(1, Cells(j, "A"), v) > 0 Then
                Cells(j, "A") = v
            End If
        Next j
    Next i
End Sub

Expand ary() as required.

OTHER TIPS

dim configSht as WorkSheet, compArray() as String, x as Integer
set configSht = thisWorkbook.Sheets("Config")'This identifies your config sheet
redim compArray(0)
for x = 1 to Cells(Rows.Count, "A").End(xlUp).Row
   if Cells(x,"A")<>"" then
       compArray(UBound(compArray) = Cells(Rows.Count, "A")

   End IF
   reDim Preserve compArray(UBound(compArray)+1)
Next

That is a very basic idea. then you'd use compArray in place of ary in @Gary's Student solution. The Comparison array would contain the information you want the cell to read after running the code. So if you are wanting "Nike Inc." for all instances of "Nike" then "Nike Inc." would be in your config.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top