Desde ya muchas gracias por la atención que pueda merecer de vuestra parte.
Adjunto un archivo en el que explico detalladamente el caso, y el ejemplo del resultado
Gracias, Jorge





Sub DistribuyeEnAreas()
Dim qCol As Integer, qRow As Long, firstR As Long, lastR As Long
Dim C As Range, mySh As Worksheet
Set mySh = ActiveSheet
qCol = Cells(1, Columns.Count).End(xlToLeft).Column
qRow = Cells(Rows.Count, "a").End(xlUp).Row
Range("a1", Cells(qRow, qCol)).Sort _
Key1:=[a1], Order1:=xlAscending, Key2:=[b1], Order2:=xlAscending, Header:=xlYes
qRow = Cells(Rows.Count, "a").End(xlUp).Row
Range("a1", Cells(qRow, 1)).AdvancedFilter xlFilterCopy, , [ag1], True
lastR = 1
On Error GoTo err_NewSheet
For Each C In Range("ag2", [ag1].End(xlDown))
With Range("a1", Cells(qRow, 1))
firstR = .Find(What:=C, After:=Cells(lastR, "a"), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False).Row
lastR = .Find(What:=C, After:=Cells(firstR, "a"), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row
End With
With Sheets(Cells(lastR, "c").Value)
Range(Cells(firstR, "a"), Cells(lastR, qCol)).Copy .Cells(Rows.Count, "a").End(xlUp).Offset(1)
End With
Next C
Set mySh = Nothing
[ag1].CurrentRegion.Delete xlShiftUp
Exit Sub
err_NewSheet:
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = mySh.Cells(lastR, "c")
mySh.Activate
Range("a1", Cells(1, qCol)).Copy Sheets(Cells(lastR, "c").Value).[a1]
Resume
End Sub





Usuarios navegando por este Foro: victor_mrc7 y 4 invitados