Hello everyone,

Eevry day I have to run a report that brings up a Workbook with a dynamic title. However, the title always contains "Course Flags Live" within it. I am trying to create a macro that will activate this workbook if it contains this text, so then I may create my other workbooks based off of this master report. Below is the code I have so far, and the "If, Then" statement is bolded. I am stumped on why it is not working. Any help would be greatly appreciated.

Sub TA_ET_Auto_ContTesting()
'
' ET_Test Macro
'
'
     
    
    Set NewBook1 = Workbooks.Add
         
    
    Set NewBook2 = Workbooks.Add
       

    Dim wb As Workbook
    If wb.Name Like "Course Flags Live" Then
    wb.Activate
    End If    
    
       
    Columns("A:P").Select
    Selection.Copy
    NewBook1.Activate
    Columns("A:A").Select
    ActiveSheet.Paste
    NewBook2.Activate
    Columns("A:A").Select
    ActiveSheet.Paste
    Range("A6").Select
    NewBook1.Activate
    Rows("1:5").Select
    Range("A5").Activate
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlUp
    Columns("J:P").Select
    Selection.Delete Shift:=xlToLeft
   
    
    
    Columns("A:A").Select
    Selection.Delete Shift:=xlToLeft
    Columns("D:D").Select
    Selection.Cut
    Columns("A:A").Select
    Selection.Insert Shift:=xlToRight
    Columns("D:D").Select
    Selection.Cut
    Columns("B:B").Select
    Selection.Insert Shift:=xlToRight
    Columns("G:G").Select
    Selection.Delete Shift:=xlToLeft
    Columns("E:E").Select
    Selection.Copy
    Columns("G:G").Select
    Selection.Insert Shift:=xlToRight
    Range("G1").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "Subscriber Key"
    Range("F1").Select
    ActiveCell.FormulaR1C1 = "Military Branch"
    Columns("C:C").Select
    Selection.Delete Shift:=xlToLeft
    Range("C1").Select
    ActiveCell.FormulaR1C1 = "Semester Start Date"
    Range("C2").Select
    NewBook2.Activate
    Rows("1:5").Select
    Range("A5").Activate
    Selection.Delete Shift:=xlUp
    Columns("J:P").Select
    Selection.Delete Shift:=xlToLeft
    Range("G:G,C:C,B:B,H:H").Select
    Range("B1").Activate
    Selection.Delete Shift:=xlToLeft
   
    Cells.Select
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("E:E" _
        ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").Sort
        .SetRange Range("A:P")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
  
    
    Columns("C:C").Select
    Selection.Cut
    Columns("B:B").Select
    Selection.Insert Shift:=xlToRight
    Range("B2").Select
  
    
    Dim lRow As Long: lRow = Range("E" & Rows.Count).End(xlUp).Row
    Dim iCntr As Long
    For iCntr = lRow To 1 Step -1
        If Format(Cells(iCntr, 5), "MM/dd/yyyy") = Format(Now(), "MM/dd/yyyy") Then
            Range("E" & iCntr).EntireRow.Delete
    End If
    Next
    
    Cells.Select
    ActiveSheet.Range("A:D").RemoveDuplicates Columns:=Array(1, 2, 3, 4), Header:=xlNo
    Columns("E:E").Select
    Selection.Delete Shift:=xlToLeft
    
    
    NewBook1.Activate
   
    
    Cells.Select
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("G:G" _
        ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").Sort
        .SetRange Range("A:P")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
   
  
    Dim lRow1 As Long: lRow1 = Range("G" & Rows.Count).End(xlUp).Row
    Dim iCntr1 As Long
    For iCntr1 = lRow1 To 1 Step -1
        If Format(Cells(iCntr1, 7), "MM/dd/yyyy") = Format(Now(), "MM/dd/yyyy") Then
            Range("G" & iCntr1).EntireRow.Delete
    End If
    Next
 
    Cells.Select
    ActiveSheet.Range("A:F").RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6), Header:=xlNo
    Columns("G:G").Select
    Selection.Delete Shift:=xlToLeft


End Sub