首页 文章

Excel宏可以在可变范围内边界单元格

提问于
浏览
0

我需要使用变量行和变量列自动化格式化导出的Excel工作表 . 看起来很简单,但我很难过 . 我只需要为表格中的所有单元格添加边框 .

我对VBA并不十分自信,但几天来一直在寻找解决方案而没有运气 . 固定范围的大量帮助,并设法实现我需要的单列,但我已经碰壁,似乎无法让整个范围工作 .

我想用英语做的例子:

向范围为“A1”的单元格添加边框,“最后一列包含第1行中的数据,最后一行包含数据在A列中”

任何帮助是极大的赞赏 .

戴夫

1 回答

  • 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
    

相关问题