如何将数据从数组或已存储的不同单元格中连接到同一个单元格中？How to concatenate data into the same cell based from an array or in different cells that are already stored?

``````Public Sub FindAndConvertforreliabilityfails()
Dim i As Integer
Dim j As Integer
Dim lastRow     As Long
Dim myRng       As Range
Dim mycell      As Range
Dim MyColl      As Collection
Dim myIterator  As Variant
Set MyColl = New Collection
Dim xpos As integr, ypos As Integer

Dim LastCol As Integer
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
For i = 1 To LastCol
For j = 1 To lastRow

For Each myIterator In MyColl
Do While Sheets(1).Cells(1, j).Value <> ""
If Sheets(1).Cells(1, i).Value = myIterator Then
xpos(j) = Sheets(1).Cells(Rows.Count, 6).End(xlUp).Offset(1, 0)
Else
ypos(j) = Sheets(1).Cells(Rows.Count, 7).End(xlUp).Offset(1, 0)
End If
Loop
Next
Next

' how to continue from here for the concatenate portion?

End Sub
``````

1 个回复1

#1楼 票数：1 已采纳

``````Private Sub Test()
Dim output As Variant
Dim outputrow As Integer
output = ""
outputrow = 0
For i = 2 To 5 'change 5 to lastrow of F&G Column.
If Cells(i, "B").Value = 0 Then
output = output & "(" & Cells(i, "F").Value & "," & Cells(i, "G").Value & "),"
Else
Cells(i, "E") = Left(output, Len(output) - 1)
output = "(" & Cells(i, "F").Value & "," & Cells(i, "G").Value & "),"
End If
Next i
Cells(i, "E") = Left(output, Len(output) - 1)
End Sub
``````

1回复

3回复

2回复

3回复

1回复

1回复

2回复

1回复