[英]Using VBA to copy a Reference to a Cell from Sheet 2 to Sheet 1
Anyone 任何人
I am new to Visual Basic Excel and would appreciate help with a particular problem. 我是Visual Basic Excel的新手,希望对特定问题有帮助。 I have been reading reference books and searching Google to find a solution but I have not been successful.
我一直在阅读参考书并搜索Google以找到解决方案,但没有成功。 I have completed all of the other project requirements except for this one.
除此项目外,我已经完成了所有其他项目要求。
I have a workbook that has 48 separate sheets and depending on which detail sheet is referenced, I need to provide information to the Summary Sheet. 我有一个工作簿,其中有48个单独的工作表,并且根据所引用的详细信息表,我需要向摘要表提供信息。 I am attempting to Copy only the Reference to Cells from a particular Detail Sheet to Summary Sheet.
我试图仅将对单元格的引用从特定的明细表复制到摘要表。 For example I am trying to have the following in Cell(15,5) on the Summary Sheet ='Detail 1'!E10 The purpose is to reference Cell(10,5) on Sheet Detail 1 so the value in the Summary Sheet updates whenever Cell(10,5) on the Detail 1 sheet changes.
例如,我试图在摘要表的单元格(15,5)='Detail 1'!E10中添加以下内容,目的是引用表单明细1的单元格(10,5),以便摘要表中的值更新每当“明细1”表上的Cell(10,5)发生变化时。
I tried this code but it does not work among a bunch of other attempts. 我尝试了这段代码,但在其他尝试中却无效。 It copies the formula but not the reference.
它复制公式,但不复制引用。
As I said before, I am still learning so, if what I show below is totally rookie code, I will suitably be embarrassed. 如前所述,我仍在学习,如果下面显示的完全是菜鸟代码,我将很尴尬。 Thank You in advance for any help.
预先感谢您的任何帮助。
'-----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
This seems like what you need 这似乎是您需要的
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.