2

我正在编写一个宏来在所有选定的工作表中插入一行,然后将一些值设置为等于另一个工作表中的值。我已经设法使用以下代码插入行,但我在尝试设置值时遇到了困难。如果没有宏,我只需输入=InputC7Input 作为工作簿中第一张工作表的名称。

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
4

2 回答 2

4

如果您只想要名为“Input”的工作表中的值,您可以这样做:

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

如果你想要公式 "=Input!C7" 你可以这样做:

CurrentSheet.Range("C7").Formula = "=Input!C7"
于 2013-06-13T18:09:44.463 回答
2

您需要使用Formula而不是Value属性,并且应该引用文本:

CurrentSheet.Range("c7").Formula "=Input!C7" 
于 2013-06-13T18:07:06.057 回答