forked from Vitosh/VBA_personal
-
Notifications
You must be signed in to change notification settings - Fork 5
/
NamedRanges.vb
102 lines (64 loc) · 1.89 KB
/
NamedRanges.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
Option Explicit
'Application.Run "Personal.xlsb!DeleteName", "NAME_HERE"
Public Sub DeleteName(sName As String)
On Error GoTo DeleteName_Error
ActiveWorkbook.Names(sName).Delete
Debug.Print sName & " is deleted!"
On Error GoTo 0
Exit Sub
DeleteName_Error:
Debug.Print sName & " not present or some error"
On Error GoTo 0
End Sub
Public Sub RemoveNamedRanges()
Dim nName As Name
Dim strNameReserved As String
On Error Resume Next
strNameReserved = "set_in_production"
For Each nName In Names
If nName.Name <> strNameReserved And Left(nName.Name, 1) <> "_" Then
Debug.Print nName.Name
nName.Delete
End If
Next nName
On Error GoTo 0
End Sub
Sub get_names_of_cells()
Dim cell As Range
On Error Resume Next
For Each cell In Selection
cell = cell.Name.Name
Next cell
On Error GoTo 0
End Sub
Sub set_names_of_cells()
Dim sample_range As Range
Dim cell As Range
Set sample_range = Selection
For Each cell In sample_range
If Not IsEmpty(cell) Then
cell.Name = cell.Text
cell.Clear
End If
Next cell
End Sub
Public Sub RemoveNamedRangesWithErrors()
Dim nName As name
Dim strNameReserved As String
On Error Resume Next
For Each nName In Names
Debug.Print nName.RefersTo
If Left(nName.RefersTo, 2) = "=#" Then
Debug.Print nName.RefersTo
'nName.Delete
End If
Next nName
On Error GoTo 0
End Sub
Sub UnhideAllNames()
Dim tempName As Name
For Each tempName In Names
'Debug.Print tempname.Name
tempName.Visible = False
Next tempName
End Sub