繁体   English   中英

使用VBA将对单元格的引用从图纸2复制到图纸1

[英]Using VBA to copy a Reference to a Cell from Sheet 2 to Sheet 1

任何人

我是Visual Basic Excel的新手,希望对特定问题有帮助。 我一直在阅读参考书并搜索Google以找到解决方案,但没有成功。 除此项目外,我已经完成了所有其他项目要求。

我有一个工作簿,其中有48个单独的工作表,并且根据所引用的详细信息表,我需要向摘要表提供信息。 我试图仅将对单元格的引用从特定的明细表复制到摘要表。 例如,我试图在摘要表的单元格(15,5)='Detail 1'!E10中添加以下内容,目的是引用表单明细1的单元格(10,5),以便摘要表中的值更新每当“明细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

这似乎是您需要的

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM