Hello,
VBA novice here. Found this code and adjusted it to fit my needs but it's not quite hitting the mark. Needs a slight tweak.
Macro is supposed to split master file in to separate ones at every change in Supervisor name. Header row is being copied to new file, but no other data. Can't figure out why.
Sample workbook attached. Thank you in advance for any and all help.
![]()
Sub MeritSplit() Application.ScreenUpdating = False Dim Rng As Range, RngList As Object, key As Variant, LastRow As Long, srcWB As Workbook Set srcWB = ThisWorkbook Set RngList = CreateObject("Scripting.Dictionary") For Each Rng In Range("A2", Range("A" & Rows.Count).End(xlUp)) If Not RngList.Exists(Rng.Value) Then RngList.Add Rng.Value, Nothing End If Next For Each key In RngList srcWB.Sheets("All Employees - 422S").Copy With ActiveSheet .Name = key LastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row .Range("A2:Y" & LastRow).Borders.LineStyle = xlNone .Cells(1, 1).CurrentRegion .Cells(1, 1).AutoFilter 1, "<>" & key .Range("A2:A" & LastRow).SpecialCells(xlCellTypeVisible).EntireRow.ClearContents End With Cells(1, 1).AutoFilter With ActiveSheet.Sort .SortFields.Clear .SortFields.Add key:=Range("A2:A" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending .SetRange Range("A2:Y" & LastRow) .Header = xlGuess .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With With ActiveSheet .Columns.AutoFit LastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row .Range("A2:Y" & LastRow).Borders.LineStyle = xlContinuous End With ActiveWorkbook.SaveAs Filename:="C:\Users\SCE01193\Desktop\Desktop\CAN Salary Planning\2023\merit files\" & key & " Merit File.xlsx", FileFormat:=51 ActiveWorkbook.Close False Next key Application.ScreenUpdating = True End Sub
Bookmarks