-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathM_select_blank_columns
More file actions
42 lines (35 loc) · 1.01 KB
/
M_select_blank_columns
File metadata and controls
42 lines (35 loc) · 1.01 KB
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
Sub Select_Blank_Columns()
'Select all entire blank Columns in selected range
'Made by kalaLokia
Dim rColumn As Range
Dim rSelect As Range
Dim rSelection As Range
'Check that a range is selected
If TypeName(Selection) <> "Range" Then
MsgBox "Please select a range first.", vbOKOnly, "Select Blank Columns Macro"
Exit Sub
End If
'Check that multiple cells are selected
If Selection.Cells.Count = 1 Then
Set rSelection = ActiveSheet.UsedRange
Else
Set rSelection = Selection
End If
'Loop through each Column and add blank Columns to rSelect range
For Each rColumn In rSelection.Columns
If WorksheetFunction.CountA(rColumn) = 0 Then
If rSelect Is Nothing Then
Set rSelect = rColumn
Else
Set rSelect = Union(rSelect, rColumn)
End If
End If
Next rColumn
'Select blank Columns
If rSelect Is Nothing Then
MsgBox "No blank Columns were found.", vbOKOnly, "Select Blank Columns Macro"
Exit Sub
Else
rSelect.Select
End If
End Sub