Trying to write a macro that will add 2 new columns (A & B) to each sheet in the workbook, adding header names & color coding, but need it to stop when it reaches the tab named "Master"
Below is the code I have so far, but keep getting a compile error in the 'Start loop' section
Sub Insert_Columns()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
On Error Resume Next
'adds new column A & B into each worksheet
ws.[a:b].Insert
'places header in new columns
ws.Range("A1").Value = "Date Deleted: After Master Tab is Created"
ws.Range("B1").Value = "Date Added: After Master Tab is Created"
'Color codes the header "RED" in column A
With ws.Range("A:A").Font
.Color = -16776961
.TintAndShade = 0
.Bold = True
End With
'Color codes the header "Green" in column B
With ws.Range("B:B").Font
.Color = -11489280
.TintAndShade = 0
.Bold = True
End With
With ws.Rows("1:1").EntireRow.AutoFit
End With
'Start loop
For Each sht In ws.Worksheets
'If worksheet in loop is the last one, stop execution (it is Master worksheet)
If sht.Index = ws.Worksheets Then
Exit For
End If
'when loop reaches "Master tab then it stops _
copying tabs to master tab
If sht.Name = "Master" Then
Exit For
End If
Next ws
End Sub
Below is the code I have so far, but keep getting a compile error in the 'Start loop' section
Sub Insert_Columns()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
On Error Resume Next
'adds new column A & B into each worksheet
ws.[a:b].Insert
'places header in new columns
ws.Range("A1").Value = "Date Deleted: After Master Tab is Created"
ws.Range("B1").Value = "Date Added: After Master Tab is Created"
'Color codes the header "RED" in column A
With ws.Range("A:A").Font
.Color = -16776961
.TintAndShade = 0
.Bold = True
End With
'Color codes the header "Green" in column B
With ws.Range("B:B").Font
.Color = -11489280
.TintAndShade = 0
.Bold = True
End With
With ws.Rows("1:1").EntireRow.AutoFit
End With
'Start loop
For Each sht In ws.Worksheets
'If worksheet in loop is the last one, stop execution (it is Master worksheet)
If sht.Index = ws.Worksheets Then
Exit For
End If
'when loop reaches "Master tab then it stops _
copying tabs to master tab
If sht.Name = "Master" Then
Exit For
End If
Next ws
End Sub