我的要求是在macro
中创建一个excel 2010
,它会使用Name Manager
(功能区>公式>名称管理器)自动为等距单元格指定或创建名称。
For e.g. Cell A1 to be named as Name_1, Cell A11 to be named as Name_2, Cell A21 to be named as Name_3 and so on.
希望这是有道理的,否则请求澄清。谢谢!
答案 0 :(得分:0)
Private Sub CommandButton1_Click()
'Define the variables
Dim vRangeDefined, vRowCount, vRowIndex, vColIndex, vCounter, vCellValue As String, vNameValue As String
'Define the range where the values are entered
vRangeDefined = ActiveSheet.Range("A:B").Value
vRowCount = ActiveSheet.UsedRange.Rows.Count
For vCounter = 2 To vRowCount
vCellValue = vRangeDefined(vCounter, 1)
vNameValue = vRangeDefined(vCounter, 2)
'Divide the Cell Value in two parts
vRowIndex = Left(vCellValue, 1)
vColIndex = Right(vCellValue, Len(vCellValue) - 1)
'MsgBox vRowIndex & "-" & vColIndex
'Assign the names to cells as per the range
ActiveWorkbook.Names.Add _
Name:=vNameValue, _
RefersTo:="='Sheet1'!$" & vRowIndex & "$" & vColIndex
Next
MsgBox "Process complete..."
End Sub