如何格式化合并单元格边框vba
所以我有一个合并的单元格,如下所示
以下是我的围绕它的代码:
Dim c As Range For Each c In testing If c.MergeCells Then c.Interior.ColorIndex = 19 c.Borders.LineStyle = xlContinuous c.Borders.Weight = xlThick c.Borders.Color = vbGreen End If Next
此代码仅在左上angular单元格周围创build边框(请参见图片)。 我如何确保边界放置在整个合并的单元格周围?
您必须使用引用范围的MergeArea
。
Dim c As Range For Each c In testing If c.MergeCells Then With c.MergeArea .Interior.ColorIndex = 19 .Borders.LineStyle = xlContinuous .Borders.Weight = xlThick .Borders.Color = vbGreen End With End If Next
尝试
With c 'Range of the merged cell .BorderAround , Weight:=xlMedium .Borders.Color = vbGreen End With