Sub ConsolidarSeguimientos(): Application.ScreenUpdating = False
primeraCopia = True
On Error Resume Next
Set destino = Sheets("Seguimiento_Anual")
If destino Is Nothing Then
Set destino = Sheets.Add
destino.Name = "Seguimiento_Anual"
Else
destino.Cells.Clear
End If
On Error GoTo 0
For Each ws In ThisWorkbook.Worksheets
If ws.Name Like "Seguimiento_*" And ws.Name <> "Seguimiento_Anual" Then
If Application.WorksheetFunction.CountA(destino.Cells) = 0 Then
ultimaFila = 1
Else
ultimaFila = destino.Cells(destino.Rows.Count, "A").End(xlUp).Row + 1
End If
If primeraCopia Then
ws.UsedRange.Copy Destination:=destino.Cells(ultimaFila, 1)
primeraCopia = False
Else
ws.UsedRange.Offset(1, 0).Resize(ws.UsedRange.Rows.Count - 1).Copy _
Destination:=destino.Cells(ultimaFila, 1)
End If
End If
Next ws
ultimaFila = destino.Cells(destino.Rows.Count, "A").End(xlUp).Row
Dim i As Long
For i = ultimaFila To 2 Step -1
If IsEmpty(destino.Cells(i, 3)) Then
destino.Rows(i).Delete
End If
Next i
With destino.Sort
.SortFields.Clear
.SortFields.Add Key:=destino.Range("A2:A" & ultimaFila), Order:=xlAscending
.SortFields.Add Key:=destino.Range("B2:B" & ultimaFila), Order:=xlAscending
.SetRange destino.Range("A1").CurrentRegion
.Header = xlYes
.Apply
End With
destino.UsedRange.Columns.AutoFit
MsgBox "Consolidación completada.", vbInformation
End Sub
Organización Formaciones Centro (1).xlsm