frustrated_macro
New Member
- Joined
- Sep 4, 2019
- Messages
- 49
- Office Version
- 365
- Platform
- Windows
i am trying to add two columns to an existing template and adding some formatting.
i am inserting a new column after A (so a new B) and a new column after M (so a new column N)
So the report initially ranged from A:N and once the new columns are inserted it should range from A:P
Well, once i run the macro, the entire report moves from A:N over to P:AC and the formatting that i did to the new B and N stay in B and N, but starting at B7 and N7 respectively (which is expected)
i jsut dont get what part of it is telling the macro to move over 15 columns
Here is the full code for it
i am inserting a new column after A (so a new B) and a new column after M (so a new column N)
So the report initially ranged from A:N and once the new columns are inserted it should range from A:P
Well, once i run the macro, the entire report moves from A:N over to P:AC and the formatting that i did to the new B and N stay in B and N, but starting at B7 and N7 respectively (which is expected)
i jsut dont get what part of it is telling the macro to move over 15 columns
Here is the full code for it
Code:
Columns("B:B").Select
Range("B3").Activate
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A3:A4").Select
Selection.Copy
Range("B3:B4").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Range("A2:C2").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Range("B6").Select
ActiveCell.FormulaR1C1 = "Date In Jeopardy?"
Range("B6").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("B7").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-1]<=RC[1],""YES"",""NO"")"
Range("B7").Select
Selection.AutoFill Destination:=Range("B7:B16")
Range("B7:B16").Select
Columns("B:B").Select
Range("B3").Activate
With Selection
.HorizontalAlignment = xlCenter
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
End With
Range("J27").Select
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 4
Columns("N:N").Select
Range("N2").Activate
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("N6").Select
ActiveCell.FormulaR1C1 = "Delivery Late?"
Range("N7").Select
Columns("N:N").ColumnWidth = 17.43
Range("N6").Select
Columns("N:N").ColumnWidth = 16.29
Range("N7").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-1]<=TODAY(),""YES,""""NO"")"
Range("N7").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-1]<=TODAY(),""YES"",""NO"")"
Range("N7").Select
Selection.AutoFill Destination:=Range("N7:N16")
Range("N7:N16").Select
Columns("N:N").Select
Range("N2").Activate
With Selection
.HorizontalAlignment = xlCenter
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
End With
ActiveWindow.Zoom = 90
ActiveWindow.Zoom = 80
ActiveWindow.ScrollColumn = 1
Range("N:N,B:B").Select
Range("B3").Activate
Cells.FormatConditions.Delete
Range("N:N,B:B").Select
Range("B3").Activate
Selection.FormatConditions.Add Type:=xlTextString, String:="YES", _
TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Range("N:N,B:B").Select
Range("B3").Activate
Selection.FormatConditions.Add Type:=xlTextString, String:="NO", _
TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Range("E27").Select
End Sub
Last edited by a moderator: