1

I have VBA code that calls a file in a folder. I am removing duplicates in the document.

I get an error because the file name is called explicity in the code. I need to call the latest file.

This is where I get the error

ActiveWorkbook.Worksheets("Target_Up_Q_Sum_RegMkt_data (1)").AutoFilter.Sort. _SortFields.Clea

I tried to call out the file using 'sheet1' and a set as workbook name as well. Was getting the same error

' portion of the code that names the latest folder
Dim wbcsv As Workbook, wbplanning As Workbook
Set wbplanning = Workbooks("Planning_tool.xlsm")
Dim wb As Workbook
Set wb = Workbooks.Open(MyPath & LatestFile)

'removing the duplicates of file need to change the name from '("Target_Up_Q_Sum_RegMkt_data (1)") to something that calls out the latest path
Cells.Select
    Selection.AutoFilter
    Range("AU1").Select
    ActiveWorkbook.Worksheets("Target_Up_Q_Sum_RegMkt_data (1)").AutoFilter.Sort. _
        SortFields.Clear
    ActiveWorkbook.Worksheets("Target_Up_Q_Sum_RegMkt_data (1)").AutoFilter.Sort. _
        SortFields.Add2 Key:=Range("AU1:AU220936"), SortOn:=xlSortOnValues, Order _
        :=xlDescending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Target_Up_Q_Sum_RegMkt_data (1)").AutoFilter. _
        Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With

I get a subscript out of range error

Community
  • 1
  • 1

0 Answers0