グリッドをソートせずに、配列をループして id が以前に見つかったかどうかを確認する必要があります。これも実行できますが、データのサイズによっては時間がかかる場合があります
'1 form with :
' 1 flexgrid control : name=grid
Option Explicit
Private Type Ids
LineId As String
CustId As String
End Type
Private Sub Form_Click()
'export to delimited string
Dim intRow As Integer
Dim intId As Integer
Dim intBound As Integer
Dim udtIds() As Ids
Dim blnThere As Boolean
Dim intCount As Integer
With grid
intBound = .Rows - 1
ReDim udtIds(intBound) As Ids
intCount = 0
For intRow = 1 To intBound
'loop through all rows
blnThere = False
For intId = 0 To intBound
'check if lineid was already found before
If udtIds(intId).LineId = .TextMatrix(intRow, 0) Then
blnThere = True
Exit For
End If
Next intId
If blnThere Then
'if lineid was already found before, just add the custid
udtIds(intId).CustId = udtIds(intId).CustId & "," & .TextMatrix(intRow, 1)
Else
'if lineid is new, then create new lineid with custid in udt
udtIds(intCount).LineId = .TextMatrix(intRow, 0)
udtIds(intCount).CustId = .TextMatrix(intRow, 1)
intCount = intCount + 1
End If
Next intRow
End With 'grid
'now you can save the udt
End Sub
Private Sub Form_Load()
With grid
'fill grid with example values
.Cols = 2
.Rows = 8
.FixedRows = 1
.FixedCols = 0
.TextMatrix(0, 0) = "LineId"
.TextMatrix(0, 1) = "CustId"
.TextMatrix(1, 0) = "1"
.TextMatrix(2, 0) = "2"
.TextMatrix(3, 0) = "7"
.TextMatrix(4, 0) = "1"
.TextMatrix(5, 0) = "3"
.TextMatrix(6, 0) = "7"
.TextMatrix(7, 0) = "1"
.TextMatrix(1, 1) = "33"
.TextMatrix(2, 1) = "98"
.TextMatrix(3, 1) = "101"
.TextMatrix(4, 1) = "51"
.TextMatrix(5, 1) = "28"
.TextMatrix(6, 1) = "02"
.TextMatrix(7, 1) = "35"
End With 'grid
End Sub