0
所以我做了一个用户表单,最终我希望能够根据用户键入到用户表单中的数字添加行。我的代码插入行,但我不知道如何将它与用户窗体和什么人类型的联合,我现在的代码是:引用用户表单
Public Sub Insert()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual 'pre XL97 xlManual
lastrow = ActiveSheet.UsedRange.Rows.Count
ActiveSheet.Cells(lastrow, 1).Select
Set CurrentCell = ActiveSheet.Cells(lastrow, 1)
For n = lastrow To 0 Step -1
If n = lastrow Then GoTo CheckLastRow
If n = 1 Then GoTo CheckfirstRow
ActiveCell.Offset(-2, 0).Select
CheckLastRow:
Set NextCell = CurrentCell.Offset(-1, 0)
ActiveCell.Offset(1, 0).Select
For i = 1 To CurrentCell
ActiveCell.EntireRow.Insert
Next i
Set CurrentCell = NextCell
Next n
'To be performed on the firstrow in the column
CheckfirstRow:
ActiveCell.Offset(-1, 0).Select
For i = 1 To CurrentCell
ActiveCell.EntireRow.Insert
Next i
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
读值你的问题和代码是有点不清楚......究竟是什么你想完成什么?您希望用户输入一个数字,然后插入许多新的行,但您希望插入的位置和次数? – FredGooch
如果用户输入5,我想插入5行。位置在选定的单元格下。谢谢你的时间 –
好吧,你的意思是这是一个单独的宏吗?你的'Insert()'代码不会做你刚才描述的内容...... – FredGooch