我有一个excel表,如下所示:
我尝试根据第一行添加外部边框,以获得以下输出:
我尝试了以下方法,但是不起作用。虽然我没有收到错误,但是Excel在运行VBA时会变得没有响应(20分钟),并且必须强制退出应用程序。我认为它运行到了一个无限循环(不确定)。
Sub shopBorder()
With ActiveSheet
Dim rng As Range, cell As Range, borderRange As Range
Set rng = .Range("A1", .Range("A" & .Columns.Count).End(xlToRight))
For Each cell In rng
If cell.MergeArea(1).Address = cell.Address Then
Set borderRange = .Range(cell.MergeArea, cell.End(xlDown).End(xlDown).End(xlDown))
AddBorder borderRange
End If
Next Cell
End With
End Sub
Public Function AddBorder(rng As Range)
rng.BorderAround _
LineStyle:=xlContinuous, _
Weight:=xlMedium
End Function
1条答案
按热度按时间bweufnob1#
如果您尝试以下操作:
您将立即看到将
rng
设置为该值的问题请尝试以下操作: