Forum Discussion

Rajeev_Raghavan's avatar
Rajeev_Raghavan
Copper Contributor
Feb 23, 2020
Solved

Macro Not working

Macro not working after the red line.   Sub Res2PR() ' ' Res2PR Macro ' Res for PR ' ' Keyboard Shortcut: Ctrl+Shift+R ' Workbooks.Open "C:\Users\rajeev.raghavan\Desktop\data\res.XLSX" Cell...
  • Riny_van_Eekelen's avatar
    Feb 23, 2020

    Rajeev_Raghavan Took your code and put it into a new workbook. Obviously, I could not run it, as I don't have your file "res.XLSX". Your code included many lines that came from the recording process (selecting cells, scrolling, reselecting cells, doing something and than re-doing it etc). I cleaned up the code and disabled the second row after "Selection.Autofilter". The row that ends with "Field:=8, Operator:=xlFilterNoFill" stopped the macro, so I put an apostrophe in front of it to make it a comment rather than an active piece of code. Now, the macro runs from start to finish, but as said, I can't test it or even imagine if this is doing what you have in mind.

    Try the code below, and let me know how it goes.

    Sub Res2PR()
    '
    ' Res2PR Macro
    ' Res for PR
    '
    ' Keyboard Shortcut: Ctrl+Shift+R
    '
        'Workbooks.Open "C:\Users\rajeev.raghavan\Desktop\data\res.XLSX"
        
        With Selection
            .VerticalAlignment = xlTop
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        
        Range("G1").Select
        ActiveCell.FormulaR1C1 = "Helper"
        
        Range("G2").Select
        ActiveCell.FormulaR1C1 = "=OR(LEFT(RC[1],1)=""6"",LEFT(RC[1],1)=""7"",LEFT(RC[1],1)=""9"")"
        Range("G2").Select
        Selection.AutoFill Destination:=Range("G2:G1803")
        
        Range("A2").Select
        Range(Selection, Selection.End(xlDown)).Select
        Range(Selection, Selection.End(xlToRight)).Select
        Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=SEARCH(""Petty"",$AC2)"
        Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        
        With Selection.FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = 65535
            .TintAndShade = 0
        End With
        
        Selection.FormatConditions(1).StopIfTrue = False
        
        Range("G1").Select
        Selection.AutoFilter
        
        ActiveSheet.Range("$A$1").AutoFilter Field:=7, Criteria1:="TRUE"
        'ActiveSheet.Range("$A$1").AutoFilter Field:=8, Operator:=xlFilterNoFill
        ActiveSheet.Range("$A$1").AutoFilter Field:=6, Criteria1:="ND"
        ActiveSheet.Range("$A$1").AutoFilter Field:=5, Criteria1:="="
        
        Range("A1:AY1803").Select
        
        Selection.Copy
        Sheets.Add After:=ActiveSheet
        ActiveSheet.Paste
        
        Columns("I:I").ColumnWidth = 21.29
        Columns("J:J").ColumnWidth = 36
        Columns("F:F").ColumnWidth = 4.57
        Columns("D:D").ColumnWidth = 4.29
        Columns("C:C").ColumnWidth = 5.86
        Columns("B:B").ColumnWidth = 6.14
        Columns("H:H").ColumnWidth = 10.43
        
        Range("A1").Select
        
        Sheets("Sheet1").Select
        Range("A1").Select
        
        Application.CutCopyMode = False
        
        ActiveCell.FormulaR1C1 = "Base date"
        Range("A1").Select
        
        Selection.AutoFilter
    End Sub

     

Resources