当“ N”放在特定单元格中时,插入“ N”个格式化行

时间:2019-03-19 13:26:50

标签: excel vba

当用户在单元格D7中输入数字N时,我试图生成N个行。这些行需要设置边框格式。 x1薄

每更改N个数字,行数也必须更改

任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

将其放置在您要在其上运行的图纸对象后面

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim NoRows As Long

    If Not Intersect(Target, Me.Range("D7")) Is Nothing Then
        With Me
            NoRows = .Range("D7").Value2
            ' Update with your reference to where the first row you want to change is
            With .Range("A1").Resize(NoRows)
                With .Borders
                    .Weight = xlThin
                    .LineStyle = xlContinuous
                End With
            End With
        End With
    End If
End Sub