AutoFit Row Height在合并的单元格上手动运行时工作,但不在VB中

我能手动自动调整行高的单元格有一个索引/匹配引用合并的单元格,但是当我使用一个macros如下所示,它将清除我自动拟合的单元格中的所有值,并设置我的合并字段值等于#value。 这是我在“采购”列的工作表1中使用的macros:

Sub AutofitMerged() Range("Sheet1[Purchases]").Select Selection.Rows.AutoFit End Sub 

这里是我在合并采购列上的工作表2中使用的函数合并单元格与公共ID是可见的(我不希望过滤的值被合并)。

 Function JoinAll(ByVal BaseValue, ByRef rng As Range, ByVal delim As String) Application.Volatile For Each a In rng If a = BaseValue And a.EntireRow.Hidden = False Then JoinAll = JoinAll & IIf(JoinAll = "", "", delim) & a(1, 6) End If Next a End Function 

在单元格我自动拟合,我使用索引/匹配从第二个工作表中获取合并的值。 第二个工作表是包含合并字段的工作表。 我的工作表使用以下架构:

工作表Sheet1

 Client ID | Purchases 1 | Purchase 1, Purchase 2 (Index/Match of Client 1 Purchases from Sheet 2) 2 | Purchase 3 (Index/Match of Client 2 Purchases from Sheet 2) 3 | Purchase 4, Purchase 5 (Index/Match of Client 3 Purchases from Sheet 2) 

工作表2

 Client ID | Purchase | Merged Purchases 1 | Purchase 1 | Purchase 1, Purchase 2 1 | Purchase 2 | Purchase 1, Purchase 2 2 | Purchase 3 | Purchase 3 3 | Purchase 4 | Purchase 4, Purchase 5 3 | Purchase 5 | Purchase 4, Purchase 5 

我的目标是在任何时候改变行高来自动调整行高,比如在图表2中input新的购买行为。我设想使用Worksheet_Calculate或其他适当的自动化function,但是这里要考虑到更大的想法。