hi all, i have the following macro that goes to particular sheets in the active workbook, creates a table if there is something on the tab, and reformats the columns. Each tab is different.
Code:
Sub TPDCleanseData()
'
' TPDCleanseData Macro
'
With ActiveWorkbook
Cells.Replace What:="null", Replacement:="", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
With Sheets("Summary")
If .Range("a6") = "" Then GoTo One
Set target = .Range("a6:AA6", .Range("A" & .Rows.Count).End(xlUp))
.ListObjects.Add(xlSrcRange, target, , xlNo, "TableStyleMedium2").Name = _
"tblSumm"
.Range("tblSumm[[Column1]:[Column1]]").NumberFormat = "0"
.Range("tblSumm[[Column3]:[Column3]]").NumberFormat = "0"
.Range("tblSumm[[Column15]:[Column17]]").NumberFormat = "0"
.Range("tblSumm[[Column23]:[Column24]]").NumberFormat = "0"
.Range("tblSumm[[Column4]:[Column14]]").Style = "Currency"
.Range("tblSumm[[Column4]:[Column14]]").NumberFormat = "_-$* #,##0_-;-$* #,##0_-;_-$* ""-""??_-;_-@_-"
.Range("tblSumm[[Column18]:[Column22]]").Style = "Currency"
.Range("tblSumm[[Column18]:[Column22]]").NumberFormat = "_-$* #,##0_-;-$* #,##0_-;_-$* ""-""??_-;_-@_-"
.Range("tblSumm[[Column25]:[Column27]]").Style = "Currency"
.Range("tblSumm[[Column25]:[Column27]]").NumberFormat = "_-$* #,##0_-;-$* #,##0_-;_-$* ""-""??_-;_-@_-"
.Cells.EntireColumn.AutoFit
.Columns("I:I").ColumnWidth = 17
.Tab.ColorIndex = 43
One:
'End If
End With
With Sheets("BAS")
If .Range("a1") = "" Then GoTo Two
.ListObjects.Add(SourceType:=xlSrcRange, Source:=.Cells(1).CurrentRegion, _
XlListObjectHasHeaders:=xlYes, TableStyleName:="TableStyleMedium2").Name = "TblBAS"
.Range("A:b,D:D,f:f,m:m,r:r,x:z,ab:ab,AD:AD").NumberFormat = "0"
.Range("S:W").Style = "Currency"
.Range("S:W").NumberFormat = "_-$* #,##0_-;-$* #,##0_-;_-$* ""-""??_-;_-@_-"
.Cells.EntireColumn.AutoFit
.Tab.ColorIndex = 43
Two:
'End If
End With
With Sheets("ITR")
If .Range("a1") = "" Then GoTo Three
.ListObjects.Add(SourceType:=xlSrcRange, Source:=.Cells(1).CurrentRegion, _
XlListObjectHasHeaders:=xlYes, TableStyleName:="TableStyleMedium2").Name = "TblITR"
.Range("A:A,C:C,D:D,S:T,AA:AB,AE:AE,av:av").NumberFormat = "0"
.Range("U:Z, AG:AG, AN:AU, AZ:BA").Style = "Currency"
.Range("U:Z, AG:AG, AN:AU, AZ:BA").NumberFormat = "_-$* #,##0_-;-$* #,##0_-;_-$* ""-""??_-;_-@_-"
.Range("Ax:AY").NumberFormat = "m/d/yyyy"
.Range("BH:BH").NumberFormat = "m/d/yyyy"
.Cells.EntireColumn.AutoFit
.Tab.ColorIndex = 43
Three:
'End If
End With
With Sheets("PAYG")
If .Range("a1") = "" Then GoTo Four
.ListObjects.Add(SourceType:=xlSrcRange, Source:=.Cells(1).CurrentRegion, _
XlListObjectHasHeaders:=xlYes, TableStyleName:="TableStyleMedium2").Name = "TblPAYG"
.Range("A:A,H:H,M:N").NumberFormat = "0"
.Range("J:L, O:S").Style = "Currency"
.Range("J:L,O:S").NumberFormat = "_-$* #,##0_-;-$* #,##0_-;_-$* ""-""??_-;_-@_-"
.Cells.EntireColumn.AutoFit
.Tab.ColorIndex = 43
Four:
'End If
End With
With Sheets("FBT")
If .Range("a1") = "" Then GoTo Five
.ListObjects.Add(SourceType:=xlSrcRange, Source:=.Cells(1).CurrentRegion, _
XlListObjectHasHeaders:=xlYes, TableStyleName:="TableStyleMedium2").Name = "TblFBT"
.Range("A:A,g:g,l:l,R:R,X:X,Z:AA").NumberFormat = "0"
.Range("S:W, Y:Y").Style = "Currency"
.Range("S:W, Y:Y").NumberFormat = "_-$* #,##0_-;-$* #,##0_-;_-$* ""-""??_-;_-@_-"
.Cells.EntireColumn.AutoFit
.Tab.ColorIndex = 43
Five:
'End If
End With
With Sheets("EMP_CNT")
If .Range("a1") = "" Then GoTo Six
.ListObjects.Add(SourceType:=xlSrcRange, Source:=.Cells(1).CurrentRegion, _
XlListObjectHasHeaders:=xlYes, TableStyleName:="TableStyleMedium2").Name = "TblEmpCnt"
.Range("A:B,E:F").NumberFormat = "0"
.Range("D:D").Style = "Currency"
.Range("D:D").NumberFormat = "_-$* #,##0_-;-$* #,##0_-;_-$* ""-""??_-;_-@_-"
.Cells.EntireColumn.AutoFit
.Tab.ColorIndex = 43
Six:
'End If
End With
With Sheets("Workcover")
If .Range("a1") = "" Then GoTo Seven
.ListObjects.Add(SourceType:=xlSrcRange, Source:=.Cells(1).CurrentRegion, _
XlListObjectHasHeaders:=xlYes, TableStyleName:="TableStyleMedium2").Name = "TblWkCover"
.Range("A:B,G:G,P:P,Z:Z").NumberFormat = "0"
.Range("E:F,U:Y").NumberFormat = "m/d/yyyy"
.Range("I:L").Style = "Currency"
.Range("I:L").NumberFormat = "_-$* #,##0_-;-$* #,##0_-;_-$* ""-""??_-;_-@_-"
.Cells.EntireColumn.AutoFit
.Tab.ColorIndex = 43
Seven:
'End If
End With
With Sheets("DETE")
If .Range("a1") = "" Then GoTo Eight
.ListObjects.Add(SourceType:=xlSrcRange, Source:=.Cells(1).CurrentRegion, _
XlListObjectHasHeaders:=xlYes, TableStyleName:="TableStyleMedium2").Name = "TblDETE"
.Range("A:a,c:c,E:E,M:N,R:R,Z:Z,AD:AE,AL:AL,AP:AP").NumberFormat = "0"
.Range("F:H,AR:AR").NumberFormat = "m/d/yyyy"
.Cells.EntireColumn.AutoFit
.Tab.ColorIndex = 43
Eight:
'End If
End With
With Sheets("BAS Benef")
If .Range("a1") = "" Then GoTo Nine
.ListObjects.Add(SourceType:=xlSrcRange, Source:=.Cells(1).CurrentRegion, _
XlListObjectHasHeaders:=xlYes, TableStyleName:="TableStyleMedium2").Name = "TblBasBen"
.Range("a:b,F:G").NumberFormat = "0"
.Range("H:H").Style = "Currency"
.Range("H:H").NumberFormat = "_-$* #,##0_-;-$* #,##0_-;_-$* ""-""??_-;_-@_-"
.Range("m:m").NumberFormat = "m/d/yyyy"
.Cells.EntireColumn.AutoFit
.Tab.ColorIndex = 43
Nine:
'End If
End With
With Sheets("TPAR")
If .Range("a1") = "" Then GoTo Ten
.ListObjects.Add(SourceType:=xlSrcRange, Source:=.Cells(1).CurrentRegion, _
XlListObjectHasHeaders:=xlYes, TableStyleName:="TableStyleMedium2").Name = "TblTPAR"
.Range("A:C,E:E,G:G,Q:R,V:V").NumberFormat = "0"
.Range("S:U").Style = "Currency"
.Range("S:U").NumberFormat = "_-$* #,##0_-;-$* #,##0_-;_-$* ""-""??_-;_-@_-"
.Cells.EntireColumn.AutoFit
.Tab.ColorIndex = 43
Ten:
'End If
End With
With Sheets("ESS")
If .Range("a1") = "" Then GoTo Eleven
.ListObjects.Add(SourceType:=xlSrcRange, Source:=.Cells(1).CurrentRegion, _
XlListObjectHasHeaders:=xlYes, TableStyleName:="TableStyleMedium2").Name = "TblESS"
.Range("a:c,E:G,I:I,K:K,T:T,X:Y,AA:AC").NumberFormat = "0"
.Range("H:H, J:J, L:M").Style = "Currency"
.Range("H:H, J:J, L:M").NumberFormat = "_-$* #,##0_-;-$* #,##0_-;_-$* ""-""??_-;_-@_-"
.Cells.EntireColumn.AutoFit
.Tab.ColorIndex = 43
Eleven:
'End If
End With
Sheets("Caveat").Activate
Range("B30").Select
End With
End Sub