5

Defining a group of cell names using vba

 2 years ago
source link: https://www.codesd.com/item/defining-a-group-of-cell-names-using-vba.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Defining a group of cell names using vba

advertisements

I have a question, I am trying to define a cell name in excel using vba. Now to select one cell only i have been using the following code which proves to work fine: Range("A1").Name = "zm_1"

However I need to name a number of cells in a column i.e:

Range("A1").Name = "zm_1" Range("A2").Name = "zm_2" Range("A3").Name = "zm_3" Range("A4").Name = "zm_4"

Since this is quite tedious for 100 cells, i have been trying to use an array:

For i=1 to 100 Range("A(i)").Name = "zm_(i)" next

^ this however gives an error which i have been unable to track. Any ideas/suggestions on how can it be done? Thanks!


The problem is with Range("A(i)").Name = "zm_(i)" The " indicate that something is text, so you should place your (i) out of the ".

For the first part it is quiet easy, as you can also use the row and column way of describing the cell. Therefore that becomes

Range(Cells(i,1)).Name

For the second part you need to concatenate the text and the numbers. That becomes: "zm_" & i


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK