Last active
August 29, 2015 14:00
-
-
Save francisluong/11192580 to your computer and use it in GitHub Desktop.
Excel VBA to Format CSV into a Table with some conditional formats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub csv_config_audit_2() | |
' | |
' csv_config_audit_2 Macro | |
' | |
' | |
Range("A1").CurrentRegion.Select | |
ActiveSheet.ListObjects.Add(xlSrcRange, Range("A1").CurrentRegion, , xlYes).Name = _ | |
"Table1" | |
Range("Table1[#All]").Select | |
ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleDark8" | |
Columns("D:D").EntireColumn.AutoFit | |
Columns("A:A").EntireColumn.AutoFit | |
Columns("B:B").EntireColumn.AutoFit | |
Columns("C:C").EntireColumn.AutoFit | |
Range("Table1[[#Headers],[template_name]]").Select | |
ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleLight13" | |
Range("Table1[#All]").Select | |
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$A1<>$A2" | |
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority | |
With Selection.FormatConditions(1).Borders(xlBottom) | |
.LineStyle = xlContinuous | |
.TintAndShade = 0 | |
.Weight = xlThin | |
End With | |
Selection.FormatConditions(1).StopIfTrue = False | |
Range("Table1").Select | |
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$B1<>$B2" | |
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority | |
With Selection.FormatConditions(1).Borders(xlBottom) | |
.LineStyle = xlContinuous | |
.TintAndShade = 0 | |
.Weight = xlThin | |
End With | |
Selection.FormatConditions(1).StopIfTrue = False | |
Range("A1").Select | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment