I have searched and tried multiple different codes and way out there, but have had no luck finding a solution. I am trying to take a macro setup to format one sheet, which works perfectly, and apply the same code to all sheets in the workbook. I have searched multiple codes and sheet array formulas but are unable to either apply them to the code I have or understand them enough to change what needs to be changed in order for them to work. I am fairly new to the macro world and do not understand the programming language at all. I appreciate anyone’s time that they put into helping me on this as I have been struggling with this for several weeks now. Thank you. The following code is what i have thus far:
Sub DARprintready()
'
' DARprintready Macro
'
'
Columns("A:A").Select
Selection.columnwidth = 2.86
Columns("B:B").Select
Selection.columnwidth = 4.57
Columns("C:C").Select
Selection.columnwidth = 13.57
Columns("D:D").Select
Selection.columnwidth = 8.57
Columns("E:E").Select
Selection.columnwidth = 20.86
Columns("F:F").Select
Selection.columnwidth = 8.43
Columns("G:H").Select
Selection.columnwidth = 9.43
Columns("I:I").Select
Selection.columnwidth = 9.14
Columns("J:J").Select
Selection.columnwidth = 9.43
Columns("K:K").Select
Selection.columnwidth = 50.4
Columns("L:L").Select
Selection.columnwidth = 9
Range("E:E,K:K").Select
Range("K1").Activate
Selection.NumberFormat = "@"
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
ActiveWindow.SmallScroll Down:=-15
Columns("A:L").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
ActiveWindow.SmallScroll Down:=-6
Columns("A:A").Select
ActiveWindow.SmallScroll Down:=-15
Range("A1").Select
Sheets("Header").Select
Range("A1:L4").Select
Selection.Copy
Sheets("Firmwide").Select
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Application.CutCopyMode = False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = "Page &P of &N"
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.18)
.RightMargin = Application.InchesToPoints(0.16)
.TopMargin = Application.InchesToPoints(0.17)
.BottomMargin = Application.InchesToPoints(0.39)
.HeaderMargin = Application.InchesToPoints(0.17)
.FooterMargin = Application.InchesToPoints(0.16)
.PrintHeadings = False
.PrintGridlines = True
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 80
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.EvenPage.LeftHeader.Text = ""
.EvenPage.CenterHeader.Text = ""
.EvenPage.RightHeader.Text = ""
.EvenPage.LeftFooter.Text = ""
.EvenPage.CenterFooter.Text = ""
.EvenPage.RightFooter.Text = ""
.FirstPage.LeftHeader.Text = ""
.FirstPage.CenterHeader.Text = ""
.FirstPage.RightHeader.Text = ""
.FirstPage.LeftFooter.Text = ""
.FirstPage.CenterFooter.Text = ""
.FirstPage.RightFooter.Text = ""
End With
End Sub
To add a bit to the other answer, use a
withstatement as a shorthand for all of your changes, so you don’t have to keep typing the sheet name over and over(you’ll have to adopt the rest of it to this form)
Also, consider keeping your column widths in an array, and assigning them to the columns in a loop. It won’t speed things up, but your code will be more compact, and, I think, readable.
E.g.,
That way, you can add more columns in at will without having to type everything out.