ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help with named-cell referencing (https://www.excelbanter.com/excel-programming/455000-help-named-cell-referencing.html)

programmernovice[_2_]

Help with named-cell referencing
 
I have two open workbooks:

SPX-BS.xlsm and

Book1.xlsm

There is a cell named "premium" in SPX-BS which I need to access from a macro to post the value to Book1. If I enter manually

'SPX-BS.xlsm'!premium into a cell on Book1 it works fine. However if, within a macro I type

Range("A7") = 'SPX-BS.xlsm'!premium

I get an "Compile Error Syntax Error" message.

Can someone please advise what I'm doing wrong? Many thanks in advance.

Claus Busch

Help with named-cell referencing
 
Hi,

Am Tue, 24 Nov 2020 11:54:10 -0800 (PST) schrieb programmernovice:

I have two open workbooks:

SPX-BS.xlsm and

Book1.xlsm

There is a cell named "premium" in SPX-BS which I need to access from a macro to post the value to Book1. If I enter manually

'SPX-BS.xlsm'!premium into a cell on Book1 it works fine. However if, within a macro I type

Range("A7") = 'SPX-BS.xlsm'!premium

I get an "Compile Error Syntax Error" message.


try:
Range("A7") = Workbooks("SPX-BS.xlsm").Sheets("Sheet1").Range("premium")

Modify the sheet name as expected.


Regards
Claus B.
--
Windows10
Office 2016

programmernovice[_2_]

Help with named-cell referencing
 
On Tuesday, November 24, 2020 at 2:20:34 PM UTC-6, Claus Busch wrote:
Hi,
Am Tue, 24 Nov 2020 11:54:10 -0800 (PST) schrieb programmernovice:

I have two open workbooks:

SPX-BS.xlsm and

Book1.xlsm

There is a cell named "premium" in SPX-BS which I need to access from a macro to post the value to Book1. If I enter manually

'SPX-BS.xlsm'!premium into a cell on Book1 it works fine. However if, within a macro I type

Range("A7") = 'SPX-BS.xlsm'!premium

I get an "Compile Error Syntax Error" message.

try:
Range("A7") = Workbooks("SPX-BS.xlsm").Sheets("Sheet1").Range("premium")

Modify the sheet name as expected.


Regards
Claus B.


Many thanks for taking time to help me out, Claus




All times are GMT +1. The time now is 09:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com