VBA / Excel方法用于在单个单元格中search/匹配60多个值

我正在做系统之间的迁移。 旧系统使用标签分类产品,新系统引入了Type。

这些数据可以作为我已经加载到Excel中的数千行的CSV提供给我。 这是一个格式的例子。

Col A | Col B | Col C Product | Type | Tags Samsung S5 | | Android, Samsung, 5.1" Screen Sony Z3 | | Android, Bluetooth, Sony, 5.2" Screen LG G3 | | Android, LG, 5.5" Screen 

我希望能够从列C中填充列B的单个标签。我可以这样做:

 A1: =IF(SEARCH("Sony",B2),"Sony", IF(SEARCH("Samsung",B2),"Samsung",etc)) 

但是,我想要将C列中的60个单独标签匹配到B列中的单个值,因此这种方法很快变得无法pipe理。

是否有另一种使用Excelfunction的方法,还是我必须使用VBA?

我很多年以来都没有使用过VBA,所以任何示例/指针都不胜感激。

是否有另一种使用Excelfunction的方法,还是我必须使用VBA?

恕我直言,VBA,试试这个:

  1. 第一个变体(比第二个变体慢)

     Sub test() Dim oCellTag As Range, oCellSource As Range For Each oCellTag In Sheets("Tags").Range("A1:A3") 'Range with Tags in one sheet For Each oCellSource In Sheets("Source").Range("C2:C4") 'Range with data for search tags in another sheet If UCase(oCellSource.Value) Like "*" & UCase(oCellTag.Value) & "*" And oCellTag.Value <> "" Then 'if cell contain tag Sheets("Source").Cells(oCellSource.Row, oCellSource.Column - 1).Value = oCellTag.Value End If Next Next End Sub 
  2. 第二个变种(快速)

     Sub test2() Dim oCellTag As Range, oCellSource As Range, KeySource, KeyTag Dim Source As Object: Set Source = CreateObject("Scripting.Dictionary") Dim Tags As Object: Set Tags = CreateObject("Scripting.Dictionary") 'Grab the dates from the WorkSheets For Each oCellTag In Sheets("Tags").Range("A1:A3") If oCellTag.Value <> "" Then Tags.Add oCellTag.Row, oCellTag.Value End If Next For Each oCellSource In Sheets("Source").Range("C2:C4") If oCellSource.Value <> "" Then Source.Add oCellSource.Row, oCellSource.Value End If Next 'Match For Each KeyTag In Tags For Each KeySource In Source If UCase(Source(KeySource)) Like "*" & UCase(Tags(KeyTag)) & "*" Then Sheets("Source").Cells(KeySource, 2).Value = Tags(KeyTag) End If Next Next End Sub