我有两列代表1:多关系。我需要将其缩减为1:1关系,其中列B中的多个项被逗号连接。下面是数据:
现在不确定如何操作。
我想通了,感谢大家。以下是代码分享:
zip code neighbors 10001 10010 10001 10011 10001 10016 10001 10018 10001 10119 10001 10199 10003 10012以下是期望的输出内容:
zip code neighbors 10001 10010, 10011, 10012, 10016, 10018, 10019, 10199由于有9000条记录,所以需要循环直到记录结束。
现在不确定如何操作。
我想通了,感谢大家。以下是代码分享:
Sub Concatenate()
Dim oldValue As String
Dim newValue As String
Dim result As String
Dim counter As Integer
oldValue = ""
newValue = ""
result = ""
counter = 1
For i = 2 To 9401
newValue = Worksheets("data").Cells(i, 1)
If (oldValue <> newValue) Then
Worksheets("result").Cells(counter, 1).NumberFormat = "@"
Worksheets("result").Cells(counter, 2).NumberFormat = "@"
Worksheets("result").Cells(counter, 1) = oldValue
Worksheets("result").Cells(counter, 2) = result
counter = counter + 1
result = ""
End If
If (result = "") Then
result = Worksheets("data").Cells(i, 2)
Else
result = result + "," + Worksheets("data").Cells(i, 2)
End If
oldValue = newValue
Next i
End Sub
1
使用集合从列表中获取唯一的邮政编码2
循环遍历唯一的集合,然后在内部循环中,循环遍历Col A。对于每个匹配项,连接值3
输出到新工作表。 - Siddharth RoutCollection/Dict/Array
更快 :) - Siddharth Rout