Sub LipoSuction2()
Dim WS As Worksheet
Dim CurrentSheet As String
Dim OldSheet As String
Dim Col As Long
Dim R As Long
Dim BottomrRow As Long
Dim EndCol As Long
Dim Pic As Object
For Each WS In Worksheets
WS.Activate
CurrentSheet = WS.Name
OldSheet = CurrentSheet & "TRMFAT"
WS.Name = OldSheet
Sheets.Add
ActiveSheet.Name = CurrentSheet
Sheets(OldSheet).Activate
For Col = 1 To Columns.Count
If Cells(Rows.Count, Col).End(xlUp).Row > BottomRow Then
BottomRow = Cells(Rows.Count, Col).End(xlUp).Row
End If
Next
For R = 1 To BottomRow
If Cells(R, Columns.Count).End(xlToLeft).Column > EndCol Then
EndCol = Cells(R, Columns.Count).End(xlToLeft).Column
End If
Next
Range(Cells(1, 1), Cells(BottomRow, EndCol)).Copy
Sheets(CurrentSheet).Activate
Range("A1").PasteSpecial xlPasteAll
Range("A1").PasteSpecial xlPasteColumnWidths
Sheets(OldSheet).Activate
For Each Pic In ActiveSheet.Pictures
Pic.Copy
Sheets(CurrentSheet).Paste
Sheets(CurrentSheet).Pictures(Pic.Index).Top = Pic.Top
Sheets(CurrentSheet).Pictures(Pic.Index).Left = Pic.Left
Next
Sheets(CurrentSheet).Activate
BottomRow = 0
EndCol = 0
Next
For Each WS In Worksheets
WS.Activate
Cells.Replace "TRMFAT", ""
Next
For Each WS In Worksheets
If Not Len(Replace(WS.Name, "TRMFAT", "")) = Len(WS.Name) Then
Application.DisplayAlerts = False
WS.Delete
Application.DisplayAlerts = True
End If
Next
End Sub
|