Excelmacros:如何更改所有行高,但是如果cell.value = bold使单元格高度更大?

我正在处理一大串使用粗体和缩进格式化的数据(B列)。 粗体单元格包含标题/类别名称,缩进的单元格值是子类别。

行高都遍布在那里。 它应该是10.5的一切,和大胆的单元格/行 15.我可以改变一切10.5,但后来我需要花相当多的时间滚动列表修改大胆的行高。 我已经使用了格式画家,但是这是一个很长的列表,我不想在这个过程中花费太多的时间。 而现在我知道我需要这样做另外30个文件。

有没有人有更快的方式做到这一点?

Sub setHeights() Dim targetRange As Range Dim targetCell As Range Set targetRange = Range("B:B") For Each targetCell In targetRange If Not IsEmpty(targetCell) Then If targetCell.Font.Bold Then targetCell.RowHeight = 15 ElseIf targetCell.Font.Superscript Then targetCell.RowHeight = 12.75 Else targetCell.RowHeight = 10.5 End If End If Next targetCell End Sub 

您可能需要将Range("B:B")更改为Table1.Range("B1:B255")

设置targetRange = Range(“B:B”),而不是如上所示设置范围

尝试像这样设置:Set TargetRange = Range(“B1”,Range(“B65536”)。End(xlUp))