使用VBA将引用复制到工作表2到工作表1

时间:2011-12-06 23:04:28

标签: excel-vba vba excel

任何

我是Visual Basic Excel的新手,非常感谢您对特定问题的帮助。我一直在阅读参考书籍并搜索谷歌寻找解决方案,但我没有成功。我完成了除此之外的所有其他项目要求。

我有一个包含48张单独工作表的工作簿,根据引用的详细信息表,我需要向摘要表提供信息。我试图仅将特定详细信息表中的参考单元复制到摘要表。例如,我试图在摘要表='详细信息1'中的单元格(15,5)中进行以下操作!E10目的是在工作表详细信息1上引用单元格(10,5),以便摘要表中的值更新每当Detail 1表上的Cell(10,5)发生变化时。

我尝试过这段代码,但它在其他一些尝试中无效。它复制公式但不复制参考。

正如我之前所说,我仍然在学习,如果我在下面展示的是完全新手的代码,我会尴尬。提前感谢您的帮助。

'-----This is simplified Version of the code in a WorkBook with 45 sheets-----------

Sub CopyReference()

Dim SheetCounter As Integer

Dim RowNumber As Integer

Dim ColumnCounter As Integer


RowNumber = 10

ColumnCounter = 5

SheetCounter = 2   '------------This is the Detail 1 Sheet in the WorkBook-------------


Sheets(SheetCounter).Select

ActiveSheet.Range(Cells(RowNumber, ColumnCounter), Cells(RowNumber, ColumnCounter)).Copy

Sheets(1).Select                   '------- This is the Summary Sheet

ActiveSheet.Range(Cells(RowNumber + 5, ColumnCounter), Cells(RowNumber + 5, ColumnCounter)).PasteSpecial Operation:=xlPasteSpecialOperationNone

End Sub

1 个答案:

答案 0 :(得分:1)

这看起来像你需要的

ThisWorkbook.Sheets(1).Cells(15, 5).Formula = "=" & _
     ThisWorkbook.Sheets(2).Cells(10, 5).Address(False, False, , True)
相关问题