请问excel如何用VBA代码在当前单元格内输入任何内容就自动设置下一行(A:G)边框(内、外框)

2025-04-11 03:04:09
推荐回答(2个)
回答1:

不知是不是要以下效果

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column < 8 Then
    i = Target.Row
    Range("a" & i + 1 & ":" & "g" & i + 1).Select
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlThick
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThick
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThick
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Weight = xlThick
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
End If
End Sub

回答2:

使用工作表事件程序的change应该可以。