Excel 2010 搜索宏以根据用户输入插入行。用户提供行号以插入行。
到目前为止,能够根据单元格的选择得到单张表的代码
希望得到一些答案......
Sub Insert_Row()
If Selection.Rows.Count > 1 Then Exit Sub
With Selection
.EntireRow.Copy
.Offset(1).EntireRow.Insert
Application.CutCopyMode = False
On Error Resume Next
.Offset(1).EntireRow.SpecialCells(xlCellTypeConstants).ClearContents
On Error GoTo 0
End With
End Sub
答案 0 :(得分:0)
编辑:
Sub Insert_Row()
Dim SelRow as Integer, i as Integer, j as Integer
If Selection.Rows.Count > 1 Then Exit Sub
SelRow = Selection.Row
On Error Goto nonNumeric
j = InputBox("What row to insert data into?", "Pick a row")
On Error GoTo 0
GoTo NumericEntry
nonNumeric:
On Error GoTo 0
MsgBox("Please try again with a number.")
Exit Sub
NumericEntry:
For i = 1 to 19
Sheets(1).Select
Rows(SelRow).copy
Sheets(i).Select
Rows(j).Insert
On Error Resume Next
Rows(j).SpecialCells(xlCellTypeConstants).ClearContents
On Error GoTo 0
Next i
End Sub