如何在顶部的每个合并单元格标题后为整个列添加垂直粗线边框?
How to add a vertical thick line border to the entire column after every merged cell heading at the top?
这是我希望它出现的样子?请为此
建议一个VBA代码
Sub FormatTest()
With Sheets("Test")
With .Range("$B:$Z")
.FormatConditions.Add xlExpression, Formula1:="=mod(row(),2)=0"
With .FormatConditions(1).Borders(xlBottom)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
.FormatConditions(1).StopIfTrue = False
End With
End With
End Sub
根据您的屏幕截图,这似乎可行。如上所述,合并单元格通常是有问题的,应尽可能避免。
Sub FormatTest()
Dim c As Long, r As Range
With Sheets("Test")
For c = 1 To .Cells(1, Columns.Count).End(xlToLeft).Column
Set r = .Cells(1, c).MergeArea
With Union(.Cells(1, c), .Columns(r(r.Columns.Count).Column))
With .Borders(xlRight)
.LineStyle = xlContinuous
.Weight = xlMedium
End With
End With
Next c
End With
End Sub
这是我希望它出现的样子?请为此
建议一个VBA代码Sub FormatTest()
With Sheets("Test")
With .Range("$B:$Z")
.FormatConditions.Add xlExpression, Formula1:="=mod(row(),2)=0"
With .FormatConditions(1).Borders(xlBottom)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
.FormatConditions(1).StopIfTrue = False
End With
End With
End Sub
根据您的屏幕截图,这似乎可行。如上所述,合并单元格通常是有问题的,应尽可能避免。
Sub FormatTest()
Dim c As Long, r As Range
With Sheets("Test")
For c = 1 To .Cells(1, Columns.Count).End(xlToLeft).Column
Set r = .Cells(1, c).MergeArea
With Union(.Cells(1, c), .Columns(r(r.Columns.Count).Column))
With .Borders(xlRight)
.LineStyle = xlContinuous
.Weight = xlMedium
End With
End With
Next c
End With
End Sub