Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the RIGHT way to reference named cells in Excel 2013 VBA? (I know I'm messing this up)

I have a cell (Ok there's a bunch but I'm just looking at one now) named "Classes". It's "C10" by Excel's grid notation.

My code works perfectly when I reference the cell as

Range("C10") = "Value"

But when I use

Classes = "Value"

It just does nothing.

So, what's the correct way to reference a named cell by its name?

like image 603
StolenKitten Avatar asked Jun 21 '13 05:06

StolenKitten


People also ask

How do you refer to a named cell in Excel VBA?

If the Excel VBA Range object you want to refer to is a single cell, the syntax is simply “Range(“Cell”)”. For example, if you want to make reference to a single cell, such as A1, type “Range(“A1″)”.

Can you reference named ranges in VBA?

Excel VBA Named Range. We can select a cell or range of cells and name it. Then, after naming the cells, we can refer to those cells by entering those defined names instead of the usual row or column references.

How do you reference a named range in Excel?

Just select the name of interest in the Excel Name Manager, and type a new reference directly in the Refers to box, or click the button at the right and select the desired range on the sheet. After you click the Close button, Excel will ask if you want to save the changes, and you click Yes.

How do you reference a named range in another worksheet?

To reference a cell or range of cells in another worksheet in the same workbook, put the worksheet name followed by an exclamation mark (!) before the cell address. For example, to refer to cell A1 in Sheet2, you type Sheet2! A1.


1 Answers

You replace the address with the named range's name:

Range("Classes") = "Value"
like image 81
Jon Crowell Avatar answered Oct 03 '22 17:10

Jon Crowell