从行到数组连接值Excel

我在Excel中有一些数据,需要从重复行转换为1行数组,即时通讯正在尝试查找>转到特殊,按值replace空白,但行不等于。

Excel数据示例:

Code Image 112001 image1.jpg 112001 image2.jpg 112001 image3.jpg 112004 image1.jpg 112004 image2jpg 554551 image1.jpg 554551 image2.jpg 554551 image3.jpg 554551 image4.jpg 

结果必须是

 Code Image 112001 image1.jpg image1.jpg,image2.jpg,image3.jpg 112001 image2.jpg 112001 image3.jpg 112004 image1.jpg image1.jpg,image2.jpg 112004 image2jpg 554551 image1.jpg image1.jpg,image2.jpg,image3.jpg,image4.jpg 554551 image2.jpg 554551 image3.jpg 554551 image4.jpg 

问题是,我有7.000行,需要编程。

有些build议做arrays是非常受欢迎的。

我玩了一小组数据,并find了下面的代码。

 Sub CompareAndOutput() Dim lastRow As Long Dim ws As Worksheet Dim row As Long, col As Long, recordCount As Long Dim output As String Dim chkStr As String, prevStr As String On Error GoTo err 'set sheet we want to use Set ws = Sheet1 'set check column to A col = 1 Application.ScreenUpdating = False Application.Calculation = xlCalculationManual lastRow = ws.Cells(ws.Rows.Count, col).End(xlUp).row 'loop through rows For row = 1 To lastRow + 1 'set column A string to compare chkStr = ws.Cells(row, col).Value 'compare string to previous value If chkStr <> prevStr Then 'output string at bottom of group ws.Cells(row - recordCount, 3).Value = output 'clear values output = "" recordCount = 0 End If 'build output string output = output & " " & ws.Cells(row, 2).Value recordCount = recordCount + 1 'set previous string for comparison next loop prevStr = chkStr Next row Application.ScreenUpdating = True Application.Calculation = xlCalculationAutomatic Exit Sub err: Application.ScreenUpdating = True Application.Calculation = xlCalculationAutomatic MsgBox err.Description, vbCritical, "An error occured" End Sub 

它循环的行和输出在组的顶部…列A组必须在一起工作,虽然..