我需要使用变量行和变量列自动化格式化导出的Excel工作表。看起来很简单,但我很难过。我只需要为表格中的所有单元格添加边框。
我对VBA并不十分自信,但几天来一直在寻找解决方案而没有运气。固定范围的大量帮助,并设法实现我需要的单列,但我已经碰壁,似乎无法使整个范围工作。
我正在尝试用英语做的例子:
为范围“A1”中的单元格添加边框,“最后一列包含第1行中的数据,最后一行包含数据在A列中”
非常感谢任何帮助。
戴夫
答案 0 :(得分:0)
也许是这样的:
Sub BoxIt()
Set r = Range("A1").CurrentRegion
With r.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With r.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With r.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With r.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With r.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With r.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
End Sub