SOLVED

Named Range behaviour in VBA

Copper Contributor

PC running Windows 10 Pro Version 20H2

Microsoft 365 Apps for business, Excel Version 2108

 

Hi All,

I'm trying to understand the behaviour of named ranges when used in VBA compared to directly in the sheet.

I have named ranges:

  • RangeA, Sheet1!C8
  • RangeB, Sheet2!B2:L2

When I enter '=RangeB' at Sheet1!C10, the entire range is entered on the sheet. If I use VBA to put '=RangeB' in the formula for different cells I get different results:

  • at Sheet1!B3, the value is 10 and the formula is '=@RangeB'
  • at Sheet1!E4, the value is 13 and the formula is '=@RangeB'
  • at RangeA, the value is 11 and the formula is  '=@RangeB'

Entered in the sheet.Entered in the sheet.By VBABy VBA

The code is:

Code for editing formulasCode for editing formulas

I've attached the workbook.

I'd like to use the named range on one worksheet to transfer the data to another sheet. I was expecting the formula when created through VBA to behave the same way as when entered in the sheet.

I'm not sure why the '@' is being inserted, or how to turn it off.
I'd appreciate any guidance on this.

Regards,

Nic

2 Replies
best response confirmed by NicJ999 (Copper Contributor)
Hi Riny, thanks for your help. Perfect solution. Exactly what I needed.
1 best response

Accepted Solutions
best response confirmed by NicJ999 (Copper Contributor)