copy value from another sheet when making a new one, and keep the reference to that cell

nemke

New Member
Joined
Aug 23, 2022
Messages
4
Office Version
  1. 2019
Platform
  1. Windows
I would like to copy the value from a cell in the existing sheet to a cell in a newly created sheet using VBA. Also, every time the value from the original cell changes, immediately to update the value in the newly created sheet. The sheet name is dynamically set, and when trying to reference it via variable, I get the dialog box for updating values, saying the sheet does not exist

For example:

Sheets(some variable).Range("A1") is always referenced to Sheets(some variable).Range("A1")

Thanks in advance
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Maybe this?
VBA Code:
Sub SimpleExample()
    Dim srcWS As Worksheet, destWS As Worksheet       'Declare worksheet variables
    Dim srcRange As Range, destRange As Range         'Declare range variables

    'Define existing sheet as source worksheet
    Set srcWS = ActiveWorkbook.Worksheets("Sheet1")

    'Create a new worksheet as destination worksheet
    Set destWS = ActiveWorkbook.Worksheets.Add

    'Set source and desitination cells
    Set srcRange = srcWS.Range("A1")
    Set destRange = destWS.Range("A1")

    'Set destination cell formula
    destRange.Formula = "=" & srcRange.Address(, , , 1)
End Sub
 
Upvote 0
Greeeeeeat, I just change the corresponding values and it worked. Thank you very much!

Can you tell what why the dialog for updating values appears? And what do those commas after "Address" in the brackets mean?
 
Upvote 0
Can you tell what why the dialog for updating values appears?
That does not happen for me, so I will need more information. What line of code produces the dialog, and what specifically does it say?

And what do those commas after "Address" in the brackets mean?
The address property has various parameters and I selected the one to produce an external reference so that the address points to a different sheet. I could have also written it as
destRange.Formula = "=" & srcRange.Address(External:=True)

 
Upvote 0

Forum statistics

Threads
1,215,129
Messages
6,123,214
Members
449,091
Latest member
jeremy_bp001

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top