根据多个工作表中的用户输入插入行

时间:2016-10-09 01:07:06

标签: excel excel-vba excel-2010 vba

Excel 2010 搜索宏以根据用户输入插入行。用户提供行号以插入行。

  1. 根据用户输入 - 要插入多个工作表(帐户,流程,数据,等等)的行有19张
  2. 从上面复制公式和格式并自动填充。
  3. 到目前为止,能够根据单元格的选择得到单张表的代码

    希望得到一些答案......

    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
    

1 个答案:

答案 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