到目前为止,我有这个。
Sub Macro1()
'
' Macro1 Macro
'
'
Range("E3").Select
ActiveWorkbook.Names.Add Name:="CGSF.COMUTIL.2", RefersToR1C1:= _
"=Sheet2!R3C5"
ActiveWorkbook.Names("CGSF.COMUTIL.2").Comment = ""
Range("F3").Select
ActiveWorkbook.Names.Add Name:="CGSF.DISTRATE.2", RefersToR1C1:= _
"=Sheet2!R3C6"
ActiveWorkbook.Names("CGSF.DISTRATE.2").Comment = ""
Range("G3").Select
ActiveWorkbook.Names.Add Name:="CGSF.CC.2", RefersToR1C1:="=Sheet2!R3C7"
ActiveWorkbook.Names("CGSF.CC.2").Comment = ""
Range("H3").Select
ActiveWorkbook.Names.Add Name:="CGSF.FUNCTION.2", RefersToR1C1:= _
"=Sheet2!R3C8"
ActiveWorkbook.Names("CGSF.FUNCTION.2").Comment = ""
End Sub
我想要的是能够提供一个起始列和一个结束列,然后让宏获取单元格名称并使其成为该单元格的范围名称。
还有一种方法可以添加名称:=“”从单元格值拉出而不是拼写出来吗?
答案 0 :(得分:0)
假设您Sheet2
来自E3 to H3
个单元格的单元格值需要转换为Named Ranges
Sub CellValue_To_NamedRange()
Dim a As Range, MyName As Range
Set a = Sheets(2).Range("E3:H3")
For Each MyName In a
ActiveWorkbook.Names.Add Name:=MyName, RefersTo:=MyName
Next
End Sub
此外,From Documentation无法通过vba
向命名范围添加注释