2017-08-02 108 views
0

美好的一天之前添加一行,执行命令按钮代码

我有这个按钮生成唯一的ID,但在执行,我想一个新的窗口,询问用户有多少行,将增加在“A20前“,那么生成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 

预先感谢您的任何输入的高度赞赏

回答

1

像这样?不知道在“A20”中加入什么意思,我认为你的意思是你将行添加到第20行?

myvalue = Inputbox("How many rows should be added?") 

For i = 1 to myvalue 
    Range("A20").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove 
Next i 

Before&After

+0

谢谢你的输入,但我只想要小区A20里添加新的细胞而不是整个A20..B20..C20 ..如果我的问题是混淆抱歉.. – N323100

+1

@ N323100修正它只是在A20添加新的单元格,现在就试试吧 - – dwirony

+0

谢谢,完美的作品! – N323100