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?
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″)”.
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.
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.
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.
You replace the address with the named range's name:
Range("Classes") = "Value"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With