Firstly, thank your to everyone who posts on this site!
I have looked through multiple forums, attempted to follow the advice, all to no avail.
So here's my simple problem: I want to run a macro that repeats the same very simple tasks (some insert columns, some formulas) on all worksheets in a workbook.
I can manually run the same macro on each individual tab, but that's not scaleable. I would rather run the macro once and have each worksheet magically updated.
So here's my code:
Sub Insert_Name_Period()
' Keyboard Shortcut: Ctrl+Shift+I
Dim ws As Worksheet
For Each ws In ThisWorkbook.Sheets
Columns("A:C").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A2").Select
ActiveCell.FormulaR1C1 = "Name"
Range("B2").Select
ActiveCell.FormulaR1C1 = "Month"
Range("C2").Select
ActiveCell.FormulaR1C1 = "Name+Month"
Range("D2").Select
Selection.Copy
Range("A2:C2").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Range("A2").Select
Columns("A:A").ColumnWidth = 15.67
Columns("B:B").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("C2").Select
Columns("C:C").ColumnWidth = 23.67
Range("A3").Select
ActiveCell.FormulaR1C1 = _
"=MID(CELL(""filename"",R[-2]C),FIND(""]"",CELL(""filename"",R[-2]C))+1,256)"
Range("A3").Select
ActiveWindow.SmallScroll Down:=186
Range("A3:A200").Select
Selection.FillDown
Range("B3").Select
ActiveCell.FormulaR1C1 = _
"=IF(OR(R[-1]C=""3 Total"",R[-1]C=""""),"""",IF(AND(R[-1]C<>1,R[-1]C<>2,R[-1]C<>3,R[-1]C<>""1 Total"",R[-1]C<>""2 Total"",R[-1]C<>""3 Total""),1,IF(AND(RC[2]<>"""",RC[4]="""",RC[12]<>""""),CONCATENATE(R[-1]C,"" Total""),IF(ISERROR(MATCH(""Total"",R[-1]C,1)),R[-1]C,R[-2]C+1))))"
Range("B3").Select
ActiveWindow.SmallScroll Down:=186
Range("B3:B201").Select
Selection.FillDown
ActiveWindow.SmallScroll Down:=-249
Range("C3").Select
ActiveCell.FormulaR1C1 = "=CONCATENATE(RC[-2],"" - "",RC[-1])"
Range("C3").Select
ActiveWindow.SmallScroll Down:=180
Range("C3:C200").Select
Selection.FillDown
Range("A2").Select
Next ws
End Sub
I have looked through multiple forums, attempted to follow the advice, all to no avail.
So here's my simple problem: I want to run a macro that repeats the same very simple tasks (some insert columns, some formulas) on all worksheets in a workbook.
I can manually run the same macro on each individual tab, but that's not scaleable. I would rather run the macro once and have each worksheet magically updated.

So here's my code:
Sub Insert_Name_Period()
' Keyboard Shortcut: Ctrl+Shift+I
Dim ws As Worksheet
For Each ws In ThisWorkbook.Sheets
Columns("A:C").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A2").Select
ActiveCell.FormulaR1C1 = "Name"
Range("B2").Select
ActiveCell.FormulaR1C1 = "Month"
Range("C2").Select
ActiveCell.FormulaR1C1 = "Name+Month"
Range("D2").Select
Selection.Copy
Range("A2:C2").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Range("A2").Select
Columns("A:A").ColumnWidth = 15.67
Columns("B:B").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("C2").Select
Columns("C:C").ColumnWidth = 23.67
Range("A3").Select
ActiveCell.FormulaR1C1 = _
"=MID(CELL(""filename"",R[-2]C),FIND(""]"",CELL(""filename"",R[-2]C))+1,256)"
Range("A3").Select
ActiveWindow.SmallScroll Down:=186
Range("A3:A200").Select
Selection.FillDown
Range("B3").Select
ActiveCell.FormulaR1C1 = _
"=IF(OR(R[-1]C=""3 Total"",R[-1]C=""""),"""",IF(AND(R[-1]C<>1,R[-1]C<>2,R[-1]C<>3,R[-1]C<>""1 Total"",R[-1]C<>""2 Total"",R[-1]C<>""3 Total""),1,IF(AND(RC[2]<>"""",RC[4]="""",RC[12]<>""""),CONCATENATE(R[-1]C,"" Total""),IF(ISERROR(MATCH(""Total"",R[-1]C,1)),R[-1]C,R[-2]C+1))))"
Range("B3").Select
ActiveWindow.SmallScroll Down:=186
Range("B3:B201").Select
Selection.FillDown
ActiveWindow.SmallScroll Down:=-249
Range("C3").Select
ActiveCell.FormulaR1C1 = "=CONCATENATE(RC[-2],"" - "",RC[-1])"
Range("C3").Select
ActiveWindow.SmallScroll Down:=180
Range("C3:C200").Select
Selection.FillDown
Range("A2").Select
Next ws
End Sub