我正在编写一个宏,以将行插入所有选定的工作表中,然后将某些值设置为等于另一工作表中的值。我已经成功使用以下代码插入了该行,但是在设置值时遇到了麻烦。如果没有宏,我只需输入=InputC7输入,即工作簿中第一张纸的名称。

Sub InsertRows()
'
' InsertRows Macro
' Inserts rows into all selected sheets at the same position
'

    Dim CurrentSheet As Object

    ' Loop through all selected sheets.
    For Each CurrentSheet In ActiveWindow.SelectedSheets
        ' Insert 1 row at row 7 of each sheet.
        CurrentSheet.Range("a7:a7").EntireRow.Insert
        CurrentSheet.Range("c7").Value =Input!C7 'this is not working
    Next CurrentSheet
End Sub

最佳答案

如果只需要名为“ Input”的工作表中的值,则可以执行以下操作:

CurrentSheet.Range("C7").Value = Sheets("Input").Range("C7").Value


如果要使用公式“ = Input!C7”,可以这样做:

CurrentSheet.Range("C7").Formula = "=Input!C7"

07-24 15:31