gpt4 book ai didi

excel - 将所有边框添加到选定范围,是否有更短的方法来编写代码?

转载 作者:行者123 更新时间:2023-12-04 12:07:42 24 4
gpt4 key购买 nike

我将所有边框添加到某个范围内,在我的情况下(A6:O6),在 excel VBA 中,下面的代码有效,但我想必须有一种更短的方法来编写它。我找到了一行代码,它在整个选择周围设置了一个边框,但不是在每个单元格周围。

Range("A6:O6").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With

最佳答案

您可以使用以下语句

Dim myRange As Range
Set myRange = Range("A6:O6")

With myRange.Borders
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With

关于excel - 将所有边框添加到选定范围,是否有更短的方法来编写代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40451623/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com