[英]Checking if a cell value exists in another cell
Sorry for the misleading title, hopefully my explanation helps you understand what I want. 对不起误导性标题,希望我的解释能帮助您了解我想要的内容。
I have three columns: 我有三列:
A B C
SKU media_gallery image_paths
LNH222A +/JPEG/LNH222A-5.jpg
LNH222B +/JPEG/LNH222A-8-ROOM.jpg
+/JPEG/LNH222B-5.jpg
+/JPEG/LNH222B-6R.jpg
....
I want to check if a cell's value within column A exists somehwere in a cell's value of column C, and if so put the matching column C cell into column B parallel to the matching string. 我想检查A列中的某个单元格的值是否存在于C列的某个单元格的值中,如果是,则将匹配的C列的单元格放入与匹配字符串平行的B列中。 So if
LNH222A
exists somewhere in column C, take that matched cell value and place it into column B. 因此,如果
LNH222A
存在于C列中的某处,请获取匹配的单元格值并将其放入B列中。
So in the example above, cell B2 should have the value of: 因此,在上面的示例中,单元格B2的值应为:
+/JPEG/LNH222A-5.jpg+/JPEG/LNH222A-8-ROOM.jpg
The same would happen for LNH222B
and so on .. 对于
LNH222B
等也会发生同样的情况。
This assumes that your data begins in row #2: 假设您的数据从第2行开始:
Sub Adrift()
Dim NA As Long, NC As Long, v As String, I As Long, J As Long
Dim v2 As String
NA = Cells(Rows.Count, "A").End(xlUp).Row
NC = Cells(Rows.Count, "C").End(xlUp).Row
For I = 2 To NA
v = Cells(I, "A").Value
v2 = ""
For J = 2 To NC
If InStr(Cells(J, "C").Value, v) > 0 Then
v2 = v2 & ";" & Cells(J, "C").Value
End If
Next J
Cells(I, "A").Offset(0, 1).Value = Mid(v2,2)
Next I
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.