|
|
|
|
|
|
Excel
|
Standardize all Cell Formats in a Workbook
|
|
Ease of Use
|
Easy
|
Version tested with
|
2002
|
Submitted by:
|
Jacob Hilderbrand
|
Description:
|
This macro makes several formatting changes to all cells in all worksheets in a workbook. Avoids the Too Many Cell Formats error.
|
Discussion:
|
You have several worksheets in a workbook and you need to make some formatting changes. This macro illustrates how to loop through every worksheet in the active workbook, domonstrates how to make several formatting changes, and helps to get rid of the Too Many Cell Formats error.
|
Code:
|
instructions for use
|
Option Explicit
Sub Formatting()
Dim WS As Worksheet
Dim RngConstants As Range
Dim RngFormulas As Range
Dim RngCell As Range
For Each WS In Worksheets
With WS.Cells
.Borders.LineStyle = xlNone
.Interior.ColorIndex = xlNone
.RowHeight = 12.75
.ColumnWidth = 8.43
With .Font
.ColorIndex = 0
.Bold = False
.Italic = False
.Underline = False
.Name = "Arial"
.Size = 10
End With
End With
With WS
On Error Resume Next
Set RngConstants = .Cells.SpecialCells(xlCellTypeConstants, 1)
Set RngFormulas = .Cells.SpecialCells(xlCellTypeFormulas, 1)
On Error GoTo 0
If Not RngConstants Is Nothing Then
For Each RngCell In RngConstants
If IsDate(RngCell.Value) Then
.Range(RngCell.Address).NumberFormat = "mm/dd/yy;@"
End If
Next
End If
If Not RngFormulas Is Nothing Then
For Each RngCell In RngFormulas
If IsDate(RngCell.Value) Then
.Range(RngCell.Address).NumberFormat = "mm/dd/yy;@"
End If
Next
End If
End With
Next
End Sub
|
How to use:
|
- Copy the code above.
- Open Excel.
- Press Alt+F11 to open the Visual Basic Editor (VBE).
- Insert-Module.
- Paste the code in the Main Code Window for that module.
- Close the VBE (Alt + Q or press the X in the top-right corner).
|
Test the code:
|
- Tools-Macro-Macros and double-click Formatting.
|
Sample File:
|
Formatting.zip 9.19KB
|
Approved by mdmackillop
|
This entry has been viewed 162 times.
|
|