我怎样才能在VBA中插入下面的行

我怎样才能在VBA中插入下面的行

我正在尝试在用户输入下方插入行,但我的代码一直将其添加到上面。谁能告诉我发生了什么......

  Dim varUserInput As Variant
  varUserInput = InputBox("Enter Row Number where you want to add a row:", _
  "What Row?")
  If varUserInput = "" Then Exit Sub

  RowNum = varUserInput
  Rows(RowNum & ":" & RowNum).Insert Shift:=xlDown

答案1

更改xlDownxlUp,如下所示:

Dim varUserInput As Variant
  varUserInput = InputBox("Enter Row Number where you want to add a row:", _
  "What Row?")
  If varUserInput = "" Then Exit Sub
  RowNum = varUserInput
  Rows(RowNum & ":" & RowNum).Insert Shift:=xlUp*

相关内容