首页 文章

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

提问于
浏览
-1

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

  • 基于用户输入 - 要插入多个工作表(帐户,流程,数据,等等)的行有19张

  • 从上面复制公式和格式并自动填充 .

到目前为止,能够根据单元格的选择获得单张表的代码

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

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

    编辑:

    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
    

相关问题