-
Notifications
You must be signed in to change notification settings - Fork 0
/
clear_wb_formatting.txt
53 lines (37 loc) · 1.91 KB
/
clear_wb_formatting.txt
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
Sub clear_wb_formatting()
' A simple macro that loops through each sheet in the given workbook clearing cell formatting (excluding number formats).
' If you need everything reset "wSheet.Cells.ClearFormats" (see below) will clear everything.
' Conditional formatting can also be removed using the below, this is commented out by default
' Updates the default "Normal" formatting for the whole workbook
With ActiveWorkbook.Styles("Normal").Font
.Name = "Calibri" 'this can be changed to any font required
.Size = 11 'as can the size
.Bold = False
.Italic = False
.Underline = xlUnderlineStyleNone
.Strikethrough = False
.Superscript = False
.ColorIndex = xlAutomatic
End With
' Loops through each sheet and clears the existing formatting,
' Returns formatting to the 'new' default set above.
Dim wSheet As Worksheet 'variable used in the 'For Loop' below
For Each wSheet In ActiveWorkbook.Worksheets
' If all you need is to clear everything uncomment the below - this will however reset date formats to numbers
' wSheet.Cells.ClearFormats
' Colour formatting
wSheet.Cells.Interior.ColorIndex = xlNone
wSheet.Cells.Font.ColorIndex = xlAutomatic
' Border formatting
wSheet.Cells.Borders.LineStyle = xlNone
wSheet.Cells.Borders.ColorIndex = xlNone
' Hyperlinks and underlines
wSheet.Cells.ClearHyperlinks
wSheet.Cells.Font.Underline = False
' Cell alignment
' wSheet.Cells.VerticalAlignment = xlTop 'reset alignment
' wSheet.Cells.HorizontalAlignment = xlLeft 'reset alignment
' Removes all conditional formatting
' wSheet.Cells.FormatConditions.Delete 'clear all conditional formating
Next wSheet
End Sub