在执行命令button代码之前添加行

美好的一天,

我有这个button生成唯一的ID,但在执行之前,我想要一个新的窗口,要求用户将添加“A20”多less行,那么生成ID的代码将在添加特定的行后执行。

这是生成ID的代码:

Private Sub CommandButton1_Click() Dim x As String, rcell As Range, y As String, z As Long x = "RFP" & Format(Now, "mmddyyhhmmss") y = Left(x, 10) z = Right(x, 2) For Each rcell In Range("D20:D" & Range("D" & Rows.Count).End(3).Row) If Cells(rcell.Row, 4) = "" Then Cells(rcell.Row, 4) = y & z z = z + 1 Next rcell End Sub 

预先感谢您的任何input,非常感谢

像这样的东西? 不知道你在“A20”中的含义是什么意思,我假设你是在第20行添加行吗?

 myvalue = Inputbox("How many rows should be added?") For i = 1 to myvalue Range("A20").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove Next i 

之前和之后