我正在尝试使用for循环在电子表格中的一系列范围周围绘制边框,除了范围的大小存储在变量中。这是我的代码:
For i = 0 To 19
Dim top_left, bottom_right As Range
Set top_left = Range("G4").Offset(0, 2 * i)
Set bottom_right = Range("H" & size).Offset(0, 2 * i)
Worksheets(3).Range(top_left & ":" & bottom_left).BorderAround ColorIndex:=1
Next
size
我的范围的垂直长度在哪里,从单元格G4向下开始,我的范围的宽度为2个单元格(因此,For循环的偏移量为2 * i)。
错误在此行上:
Worksheets(3).Range(top_left & ":" & bottom_left).BorderAround ColorIndex:=1
我试过将范围转换为地址或字符串,但不起作用。有任何想法吗?
首先,您在错误行中写入了“ bottom_left”,但“ bottom_left”不存在。我想您想写“ bottom_right”,不是吗?
其次,“ top_left”和“ bottom_right”不代表“ A1”这样的地址,它们包含该值。您不能将它们与“ Range(”一起使用。
尝试以下方法:
Worksheets(3).Range(top_left.Address & ":" & bottom_right.Address).BorderAround ColorIndex:=1
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句