Skip to content

Instantly share code, notes, and snippets.

@francisluong
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save francisluong/11192580 to your computer and use it in GitHub Desktop.
Save francisluong/11192580 to your computer and use it in GitHub Desktop.
Excel VBA to Format CSV into a Table with some conditional formats
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