Macro moving all columns over 15 columns

frustrated_macro

New Member
Joined
Sep 4, 2019
Messages
49
Office Version
  1. 365
Platform
  1. 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
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:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Do you run this macro after the code I am helping you with in your other thread?
 
Upvote 0
I don't follow what you're trying to do, but...

I'd suggest you split your screen, half with the sheet in one window and the other half with the macro in another window.
If you don't already know how to do that... bring the sheet up on the screen then hit the Window key and Left arrow key together, then bring the vba up on the screen and hit the Window key and Right arrow.
Now if you place the cursor within the macro and use the F8 key to step through the macro a line at a time and you will see in the sheet window what is happening with the execution of each line and can perhaps figure out where whatever it is you're looking for is happening.
 
Upvote 0
The macro testers secret weapon :biggrin:
You're very welcome.
 
Upvote 0
Might also be a bit quicker....UNTESTED....in the car

Code:
Sub MM1()
Columns("B:B").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("A3:A4").Copy
    Range("B3:B4").Select
    Selection.PasteSpecial Paste:=xlPasteFormats
    Range("A2:C2").Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    Range("B6").Value = "Date In Jeopardy?"
    With Range("B6")
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
    End With
    Range("B7:B16").Formula = "=IF(A7<=C7,""YES"",""NO"")"
    Columns("B:B").HorizontalAlignment = xlCenter
    Columns("N:N").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("N6").Value = "Delivery Late?"
    Columns("N:N").ColumnWidth = 16.29
    Range("N7:N16").Formula = "=IF(M7<=TODAY(),""YES"",""NO"")"
   Columns("N:N").HorizontalAlignment = xlCenter
    ActiveWindow.Zoom = 80
    Range("N:N,B:B").FormatConditions.Delete
    Range("N:N,B:B").FormatConditions.Add Type:=xlTextString, String:="YES", _
        TextOperator:=xlContains
    Range("N:N,B:B").FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Range("N:N,B:B").FormatConditions(1).Font
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = 0
    End With
    With Range("N:N,B:B").FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 255
        .TintAndShade = 0
    End With
    Range("N:N,B:B").FormatConditions(1).StopIfTrue = False
    Range("N:N,B:B").FormatConditions.Add Type:=xlTextString, String:="NO", _
        TextOperator:=xlContains
    Range("N:N,B:B").FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Range("N:N,B:B").FormatConditions(1).Font
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = 0
    End With
    Range("N:N,B:B").FormatConditions(1).StopIfTrue = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,217,422
Messages
6,136,545
Members
450,020
Latest member
ddobrzynski

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top