简体   繁体   English

如何遍历单元格范围并在vba中用单元格值命名单元格?

[英]How do I loop through a cell range and name the cells with cell value in vba?

I have the following code and it works well, however, I'd like to loop through a cell range and name the cells in the range with the cell value: 我有以下代码,它运行良好,但是,我想遍历一个单元格范围,并用该单元格值命名该范围内的单元格:

Sub NameCell()
Range("A2").Name = Range("A2").Value
End Sub

Give this a try: 试试看:

Sub NameMaker()
    For Each r In Selection
        With r
            .Name = .Value
        End With
    Next r
End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 VBA 如何根据该范围内一个单元格的值有条件地格式化一系列单元格? - VBA How do I conditionally format a range of cells based on the value of one cell in that range? 如何在循环显示一系列单元格时获取当前单元格编号(Excel VBA) - How do I get the current cell number whilst looping through a range of cells (Excel VBA) 循环遍历一系列单元格并更改单元格值的语法 - Syntax to loop through a range of cells and change a cell value 如何在 VBA 的不同工作表中将一系列单元格值设置为另一个单元格范围? - How do I set a range of cell values to another range of cells in a different worksheet in VBA? Excel VBA如何将WorkSheet名称与单元格值匹配,然后复制并粘贴一系列单元格 - Excel VBA How to match WorkSheet name with Cell value, then Copy and Paste a Range of Cells VBA遍历范围并替换相邻行单元格中的值 - VBA Loop through range and replace value in adjacent row cell 我如何在VBA中编写一个循环,如果一个范围内的单元格及其旁边的单元格都等于一个常数,它将删除一行? - How do I write a loop in VBA that will delete a row if a cell in a range and the cell next to it both equal a constant? VBA如何匹配单元格与相邻单元格的范围和返回值? - vba how to match cell with range and return value in adjacent cells? 在单元格更改时循环一系列单元格,以将序列中的下一个数字显示为单元格的新值 - Loop through a range of cells on cell change to show next number in the sequence as cell's new value 如何遍历范围直到单元格为空在Excel VBA中 - How to loop through a range until a cell is empty In Excel VBA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM