我需要一个宏,该宏根据A列中的格式在A到F的单元格区域中放置边框。在“ A”列中,单元格可以与其下方的多个单元格合并,也可以只是一个单元格。我已经编写了VBA代码,在A列的非空白单元格周围放置了边框,但不知道如何将其扩展到其他5列(从B到F)。查看图片以更好地了解我写的内容和需要的内容。
数据的样子:数据
我的代码做什么:WhatMyCodeDoes
我想要它做什么:WhatIWantItToDo
我的代码:
Sub Borders()
Dim linestyle As Variant, line As Variant
Range("A1").Select
Do While ActiveCell.Address <> Range("A65536").End(xlUp).Offset(1, 0).Address
If ActiveCell.Value > 0 Then
linestyle = Array(xlDiagonalDown, xlDiagonalUp, xlInsideVertical, xlInsideHorizontal)
line = Array(xlEdgeLeft, xlEdgeTop, xlEdgeBottom, xlEdgeRight)
For I = 0 To UBound(linestyle)
Selection.Borders(linestyle(I)).linestyle = xlNone
With Selection.Borders(line(I))
.linestyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
Next I
Else
End If
ActiveCell.Offset(1, 0).Select
Loop
End Sub
您可以只更改两行,就可以了。
'Range("A1").Select
Range("A1").Resize(1, 6).Select
' ...
'ActiveCell.Offset(1, 0).Select
ActiveCell.Offset(1, 0).Resize(1, 6).Select
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句