-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathExcel VBA - Quick lines for Table.vb
56 lines (47 loc) · 1.44 KB
/
Excel VBA - Quick lines for Table.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
Sub create_Table_Borders()
'Set range for borders
Dim j As Range
Set j = Range("B2:D10")
'Store areas
Dim elements(5) As String
elements(0) = xlEdgeBottom
elements(1) = xlEdgeTop
elements(2) = xlEdgeLeft
elements(3) = xlEdgeRight
elements(4) = xlInsideHorizontal
elements(5) = xlInsideVertical
'Implement
For Each w In elements
j.Cells.Borders(w).LineStyle = xlContinuous
j.Cells.Borders(w).Weight = xlThin
'
' Optional
'
'Medium weight borders around table
If w = xlEdgeTop Or w = xlEdgeBottom Or w = xlEdgeLeft Or w = xlEdgeRight Then
j.Cells.Borders(w).Weight = xlMedium
End If
Next
End Sub
Sub create_Table_BordersAnywhere()
'Get current range selected
Dim current_Selection As Range
Set current_Selection = Selection
'Set in range
Dim create_Table As Range
Set create_Table = Range(current_Selection.Address)
Dim elements(5) As String
elements(0) = xlEdgeBottom
elements(1) = xlEdgeTop
elements(2) = xlEdgeLeft
elements(3) = xlEdgeRight
elements(4) = xlInsideHorizontal
elements(5) = xlInsideVertical
For Each w In elements
j.Cells.Borders(w).LineStyle = xlContinuous
j.Cells.Borders(w).Weight = xlThin
If w = xlEdgeTop Or w = xlEdgeBottom Or w = xlEdgeLeft Or w = xlEdgeRight Then
j.Cells.Borders(w).Weight = xlMedium
End If
Next
End Sub