I have this problem that I am trying to solve. every day I get a report containing the data that I need to send forward. Therefore, to make this a little easier, I tried to find a macro that creates a new sheet with the name of the agent and moves the data for each agent in the created sheet ...
I found one that would suggest doing pretty much that. But since this is not my area of โโexpertise, I cannot change it to process my request, and even make it work, probably. Does anyone have an idea?
Const cl& = 2 Const datz& = 1 Dim a As Variant, x As Worksheet, sh As Worksheet Dim rws&, cls&, p&, i&, ri&, j& Dim u(), b As Boolean, y Application.ScreenUpdating = False Sheets("Sheet1").Activate rws = Cells.Find("*", , , , xlByRows, xlPrevious).Row cls = Cells.Find("*", , , , xlByColumns, xlPrevious).Column Set x = Sheets.Add(After:=Sheets("Sheet1")) Sheets("Sheet1").Cells(1).Resize(rws, cls).Copy x.Cells(1) Set a = x.Cells(1).Resize(rws, cls) a.Sort a(1, cl), 2, Header:=xlYes a = a.Resize(rws + 1) p = 2 For i = p To rws + 1 If a(i, cl) <> a(p, cl) Then b = False For Each sh In Worksheets If sh.Name = a(p, cl) Then b = True: Exit For Next If Not b Then Sheets.Add.Name = a(p, cl) With Sheets(a(p, cl)) x.Cells(1).Resize(, cls).Copy .Cells(1) ri = i - p x.Cells(p, 1).Resize(ri, cls).Cut .Cells(2, 1) .Cells(2, 1).Resize(ri, cls).Sort .Cells(2, datz), Header:=xlNo y = .Cells(datz).Resize(ri + 1) ReDim u(1 To 2 * ri, 1 To 1) For j = 2 To ri u(j, 1) = j If y(j, 1) <> y(j + 1, 1) Then u(j + ri, 1) = j Next j .Cells(cls + 1).Resize(2 * ri) = u .Cells(1).Resize(2 * ri, cls + 1).Sort .Cells(cls + 1), Header:=xlYes .Cells(cls + 1).Resize(2 * ri).ClearContents End With End If p = i End If Next i Application.DisplayAlerts = False x.Delete Application.DisplayAlerts = True Application.ScreenUpdating = True
This is an example of my report, which I get an example

I keep getting the error in the line: a.Sort a (1, cl), 2, Header: = xlYes This I myself do not know what it does. Can anyone explain?