VBA/Excel/Access/Word/Excel/Name Create — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 12:47, 26 мая 2010
Содержание
- 1 Add the name to the Names collection associated with the worksheet, which only includes the names that are local to that worksheet
- 2 create a global name that refers to a range using the Add method of the Workbook object"s Names collection
- 3 Create a local name
- 4 Create a name based on a Range
- 5 Define a name by referring a workbook
- 6 Define a name by referring the selection cell address
- 7 renames an existing name:
Add the name to the Names collection associated with the worksheet, which only includes the names that are local to that worksheet
Sub nameRef()
Worksheets("Sheet1").Names.add name:="Costs", RefersTo:="=Sheet1!$F$10:$F$12"
End Sub
"Using the Name Property of the Range Object
Sub name()
range("A1:D10").name = "SalesData"
End Sub
create a global name that refers to a range using the Add method of the Workbook object"s Names collection
Sub add()
Names.add name:="Data", RefersTo:="=Sheet1!$D$10:$D$12"
End Sub
Create a local name
Sub localDemo()
Names.add name:="Sheet1!Sales", RefersTo:="=Sheet1!$E$10:$E$12"
End Sub
Create a name based on a Range
Sub nameName()
range("A1:F6").name = "Fruits"
End Sub
Define a name by referring a workbook
Sub DefineName3()
ActiveWorkbook.names.Add Name:="WorkArea", RefersTo:="=" + ActiveWorkbook.Sheets("sheet1").[A1].CurrentRegion.Address(External:=True)
Debug.Print Range("WorkArea").Address(External:=True)
End Sub
Define a name by referring the selection cell address
Sub DefineName2()
ActiveWorkbook.Activate
[A1].CurrentRegion.Activate
ActiveWorkbook.Names.Add Name:="WorkArea", RefersTo:="=" + Selection.Address
Debug.Print Range("WorkArea").Address(External:=True)
End Sub
renames an existing name:
Sub nameName2()
Names("Fruits").name = "Produce"
End Sub