用於將多行合併為多列之一的VBA?

用於將多行合併為多列之一的VBA?

對於這麼長的帖子,我深表歉意,但我想包含盡可能多的信息。我可以在網上找到一些信息,但我需要幫助更改。以下是我需要合併的資料範例:

我需要合併這張表:

第1部分 第2部分 滿的 報告 HRO列車 時間經理 出席者 預定 客戶名稱 客戶ID 客戶端遷移器 導師
1/7/21 1/7/21 1/7/21 簡·無名氏 21/2/2 簡·多伊公司 123456789 莎拉 蘇珊
1/8/21 1/8/21 1/8/21 簡·無名氏 21/2/2 簡·多伊公司 123456789 莎拉 蘇珊
1/7/21 1/7/21 1/7/21 約翰·迪伊 21/3/1 約翰·迪伊 321654987 拉里 鮑伯
1/8/21 1/8/21 1/8/21 約翰·迪伊 21/3/1 約翰·迪伊 321654987 拉里 鮑伯

進入這個表:

第1部分 第2部分 滿的 報告 HRO列車 時間經理 出席者 預定 客戶名稱 客戶ID 客戶端遷移器 導師
1/7/21 1/7/21 1/8/21 1/8/21 1/7/21 1/8/21 簡·無名氏 21/2/2 簡·多伊公司 123456789 莎拉 蘇珊
21/1/7;21/1/8 21/1/7;21/1/8 1/7/21 1/8/21 約翰·迪伊 21/3/1 約翰·迪伊 321654987 拉里 鮑伯

我發現這個線程了解如何建立執行此類組合的 VBA,但我的數據有點不同,我不確定如何更改程式碼以實現此目的。我將複製貼上以下程式碼:

'Dim 2 search cells
Dim BlankCell As Range
Dim IdCell As Range
'Find Last row and column
Dim lRow As Long
lRow = Range("A1").End(xlDown).Row
Dim lColumn As Long
lColumn = Range("A1").End(xlToRight).Column
'Set the area to consider
Dim Rng As Range
Set Rng = Range(Cells(1, 1), Cells(lRow, lColumn))
'Select​ each blank cell in area
Rng.Select
Selection.SpecialCells(xlCellTypeBlanks).Select
'And replace it with appropriate value
For Each BlankCell In Selection
For Each IdCell In Range(Cells(1, 1), Cells(lRow, 1))
If (IdCell.Value = Cells(BlankCell.Row, 1).Value And Cells(IdCell.Row, BlankCell.Column) <> "") Then
BlankCell = Cells(IdCell.Row, BlankCell.Column).Value
End If
Next IdCell
Next BlankCell
'Then​ erase duplicate lines
Rng.Select
ActiveSheet.Range(Cells(1, 1), Cells(lRow, lColumn)).RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6), _
Header:=xlYes

使用此 VBA,它使用 A 列作為要匹配的標識符來合併行。但是,我需要 VBA 來匹配 G 列作為標識符,並且我不確定在哪裡編輯以更改該列。對於我需要用“;”組合所有日期的情況分隔符,我認為這個 VBA 不能解決這種情況。我還需要添加什麼才能成功實現這一目標?太感謝了!

相關內容