/
workbook-cleanup
192 lines (142 loc) · 4.32 KB
/
workbook-cleanup
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
Sub ClearNames()
Dim oName As Name
UserForm1.Show
Sheets(1).Select
For Each oName In ActiveWorkbook.Names
oName.Delete
'oName.Visible = True
Next oneName
End Sub
Sub RidofCondFormat()
UserForm1.Show
For i = 1 To ActiveWorkbook.Worksheets.count
ActiveWorkbook.Sheets(i).Activate
ActiveSheet.Cells.FormatConditions.Delete
Next i
End Sub
Sub Collapse_All()
UserForm1.Show
SheetCount = ActiveWorkbook.Worksheets.count
For i = 1 To SheetCount
'Close groups
If ActiveWorkbook.Worksheets(i).Visible = True Then
ActiveWorkbook.Worksheets(i).Select 'Replace:=False
Else: GoTo Next1
End If
ActiveWorkbook.Worksheets(i).Select
ActiveSheet.Outline.ShowLevels RowLevels:=1, ColumnLevels:=1
'Home position or VBA equivalent of Ctrl+Home (not always A1)
ActiveWindow.ScrollRow = 1
ActiveWindow.ScrollColumn = 1
ActiveWindow.ActivePane.VisibleRange.Cells(1).Select
Next1:
Next i
'Selects first visible worksheet to avoid selection error
For i = 1 To SheetCount
If ActiveWorkbook.Worksheets(i).Visible = True Then
ActiveWorkbook.Worksheets(i).Select
Exit For
End If
Next i
End Sub
Sub Expand_All()
UserForm1.Show
SheetCount = ActiveWorkbook.Worksheets.count
For i = 1 To SheetCount
'Close groups
If ActiveWorkbook.Worksheets(i).Visible = True Then
ActiveWorkbook.Worksheets(i).Select 'Replace:=False
Else: GoTo Next1
End If
ActiveWorkbook.Worksheets(i).Select
ActiveSheet.Outline.ShowLevels RowLevels:=8, ColumnLevels:=8
Next1:
Next i
'Selects first visible worksheet to avoid selection error
For i = 1 To SheetCount
If ActiveWorkbook.Worksheets(i).Visible = True Then
ActiveWorkbook.Worksheets(i).Select
Exit For
End If
Next i
End Sub
Sub ReplaceIndexMatch()
'Finds "index(" in active sheet, Ctrl + Shift + Down, and copy paste special values.
'Be careful if you have different formulas under!
UserForm1.Show
Application.ScreenUpdating = False
Application.DisplayAlerts = False
With ActiveSheet.UsedRange
Set C = .Find("index(", LookIn:=xlFormulas)
If Not C Is Nothing Then
firstaddress = C.Address
Do
C.Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
Set C = .FindNext(C)
If C Is Nothing Then
GoTo DoneFinding
End If
Loop While Not C Is Nothing And C.Address <> firstaddress
End If
DoneFinding:
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
Application.DisplayAlerts = True
ThisWorkbook.ActiveSheet.Activate
End Sub
Sub ReplaceSumifs()
'Finds "sumif" in active sheet and replaces with value.
UserForm1.Show
Application.ScreenUpdating = False
Application.DisplayAlerts = False
With ActiveSheet.UsedRange
Set C = .Find("sumif", LookIn:=xlFormulas)
If Not C Is Nothing Then
firstaddress = C.Address
Do
C.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
Set C = .FindNext(C)
If C Is Nothing Then
GoTo DoneFinding
End If
Loop While Not C Is Nothing And C.Address <> firstaddress
End If
DoneFinding:
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
Application.DisplayAlerts = True
ThisWorkbook.ActiveSheet.Activate
End Sub
Sub Replacevlookup()
'Finds "vlookup(" in active sheet and replaces with value.
UserForm1.Show
Application.ScreenUpdating = False
Application.DisplayAlerts = False
With ActiveSheet.UsedRange
Set C = .Find("vlookup(", LookIn:=xlFormulas)
If Not C Is Nothing Then
firstaddress = C.Address
Do
C.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
Set C = .FindNext(C)
If C Is Nothing Then
GoTo DoneFinding
End If
Loop While Not C Is Nothing And C.Address <> firstaddress
End If
DoneFinding:
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
Application.DisplayAlerts = True
ThisWorkbook.ActiveSheet.Activate
End Sub