Excel file with the size 20MB

jam42a34

New Member
Joined
Aug 3, 2009
Messages
3
Hi There

Can you please assist me in this case as below:

I created a new excel file with filtering and after i saved the file , i found that the size for this excel file is 19 MB, so is this normal size for an excel file or there is a problem in this file and i have to fix it

Can you please update me back
Thanks and Regards
 
Re: Excle file with the size 20MB

Blade Hunter, I've just got to say thank you very much! I had a file that I created about 4 years ago when I knew very little about Excel which ended up growing to around 60mb. No matter what I tried I couldn't get it any smaller! I tried several pieces of code I found here on Mr Excel and yours is the only one that worked - my file is now down to just over 1mb!
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Re: Excle file with the size 20MB

Hi Guys, this didn't work for us in Excel 2007. I have written an alternative, I hope it is useful to someone.

You can change TRMFAT to whatever you want, just make sure you replace it everywhere.

The problem you will find with this code is if your sheet names are as long as the limit. We have not encountered this but you could easily set up a bunch of variables and do it that way.

Rich (BB code):
Sub LipoSuction2()
'Written by Daniel Donoghue 18/8/2009
'The purpose of this code is to offer an alternative to the original Liposuction code written by JBeaucaire for the MrExcel forums www.mrexcel.com
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
For Each WS In Worksheets
    WS.Activate
    'Put the sheets in a variable to make it easy to go back and forth
    CurrentSheet = WS.Name
    'Rename the sheet to its name with TRMFAT at the end
    OldSheet = CurrentSheet & "TRMFAT"
    WS.Name = OldSheet
    'Add a new sheet and call it the original sheets name
    Sheets.Add
    ActiveSheet.Name = CurrentSheet
    Sheets(OldSheet).Activate
    'Find the bottom cell of data on each column and find the further row
    For Col = 1 To Columns.Count 'Find the REAL bottom row
        If Cells(Rows.Count, Col).End(xlUp).Row > BottomRow Then
            BottomRow = Cells(Rows.Count, Col).End(xlUp).Row
        End If
    Next
    'Find the end cell of data on each row that has data and find the furthest one
    For R = 1 To BottomRow 'Find the REAL most right column
        If Cells(R, Columns.Count).End(xlToLeft).Column > EndCol Then
            EndCol = Cells(R, Columns.Count).End(xlToLeft).Column
        End If
    Next
    'Copy the REAL set of data
    Range(Cells(1, 1), Cells(BottomRow, EndCol)).Copy
    Sheets(CurrentSheet).Activate
    'Paste everything
    Range("A1").PasteSpecial xlPasteAll
    'Paste Column Widths
    Range("A1").PasteSpecial xlPasteColumnWidths
    'Reset the variable for the next sheet
    BottomRow = 0
    EndCol = 0
Next
'Excel will automatically replace the sheet references for you on your formulas, the below part puts them back
'This is done with a simple reaplce, replacing TRMFAT with nothing
For Each WS In Worksheets
    WS.Activate
    Cells.Replace "TRMFAT", ""
Next
'Poll through the sheets and delete the original bloated sheets
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

This code will basically rename your sheet to have TRMFAT after it and Excel will auto update referencing formulas. It will then create a new sheet with the name of the original sheet and paste the data and column widths in to it before moving on to the next sheet.

Once it has done all sheets it looks through the new sheets and replaces TRMFAT in all the formulas with "", this will point the formulas to the NEW copies of the sheets.

Finally the original sheets are deleted.

Do make sure you test this on a COPY first.

This relies on the last cell and row of data actually having real data. Maybe someone on here can improve on the code to ensure that there really is data in it and not some random unresolved formula.

Cheers

Dan

Is there a way ot run this code but leave the pictures remaining? I have a report to run that was 14 MB. I ran lipo and now it's 80 KB but it deleted my company logos.
 
Upvote 0
Re: Excle file with the size 20MB

Without adding tons of custom code, can't you just reinsert the logos now that the file has been trimmed?
 
Upvote 0
I can, I just wasn't sure how easy it would be to format some code to exclude excision of the logos.
 
Upvote 0
Give this a go on a copy of your sheet and report back please:

Rich (BB code):
Sub LipoSuction2()
'Written by Daniel Donoghue 18/8/2009
'The purpose of this code is to offer an alternative to the original Liposuction code written by JBeaucaire for the MrExcel forums www.mrexcel.com
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
'Begin addition 6/4/2010 for request: http://www.mrexcel.com/forum/showthread.php?p=2269274#post2269274
Dim Pic As Object
'End Addition 6/4/2010 for request: http://www.mrexcel.com/forum/showthread.php?p=2269274#post2269274
For Each WS In Worksheets
    WS.Activate
    'Put the sheets in a variable to make it easy to go back and forth
    CurrentSheet = WS.Name
    'Rename the sheet to its name with TRMFAT at the end
    OldSheet = CurrentSheet & "TRMFAT"
    WS.Name = OldSheet
    'Add a new sheet and call it the original sheets name
    Sheets.Add
    ActiveSheet.Name = CurrentSheet
    Sheets(OldSheet).Activate
    'Begin addition 6/4/2010 for request: http://www.mrexcel.com/forum/showthread.php?p=2269274#post2269274
    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
    'End Addition 6/4/2010 for request: http://www.mrexcel.com/forum/showthread.php?p=2269274#post2269274
    'Find the bottom cell of data on each column and find the further row
    For Col = 1 To Columns.Count 'Find the REAL bottom row
        If Cells(Rows.Count, Col).End(xlUp).Row > BottomRow Then
            BottomRow = Cells(Rows.Count, Col).End(xlUp).Row
        End If
    Next
    'Find the end cell of data on each row that has data and find the furthest one
    For R = 1 To BottomRow 'Find the REAL most right column
        If Cells(R, Columns.Count).End(xlToLeft).Column > EndCol Then
            EndCol = Cells(R, Columns.Count).End(xlToLeft).Column
        End If
    Next
    'Copy the REAL set of data
    Range(Cells(1, 1), Cells(BottomRow, EndCol)).Copy
    Sheets(CurrentSheet).Activate
    'Paste everything
    Range("A1").PasteSpecial xlPasteAll
    'Paste Column Widths
    Range("A1").PasteSpecial xlPasteColumnWidths
    'Reset the variable for the next sheet
    BottomRow = 0
    EndCol = 0
Next
'Excel will automatically replace the sheet references for you on your formulas, the below part puts them back
'This is done with a simple reaplce, replacing TRMFAT with nothing
For Each WS In Worksheets
    WS.Activate
    Cells.Replace "TRMFAT", ""
Next
'Poll through the sheets and delete the original bloated sheets
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

Seems to work OK to me but I had limited data to test with.

Note, if you have further requests ie retain hyperlinks from picture etc etc please post back to this thread, When a new request is made I will update the code accordingly.
 
Upvote 0
Use this one instead, it makes sure the location of the pic is the same (Old one would have been affected if the columns were anything other than default size).

Rich (BB code):
Sub LipoSuction2()
'Written by Daniel Donoghue 18/8/2009
'The purpose of this code is to offer an alternative to the original Liposuction code written by JBeaucaire for the MrExcel forums www.mrexcel.com
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
'Begin addition 6/4/2010 for request: http://www.mrexcel.com/forum/showthread.php?p=2269274#post2269274
Dim Pic As Object
'End Addition 6/4/2010 for request: http://www.mrexcel.com/forum/showthread.php?p=2269274#post2269274
For Each WS In Worksheets
    WS.Activate
    'Put the sheets in a variable to make it easy to go back and forth
    CurrentSheet = WS.Name
    'Rename the sheet to its name with TRMFAT at the end
    OldSheet = CurrentSheet & "TRMFAT"
    WS.Name = OldSheet
    'Add a new sheet and call it the original sheets name
    Sheets.Add
    ActiveSheet.Name = CurrentSheet
    Sheets(OldSheet).Activate
    'Find the bottom cell of data on each column and find the further row
    For Col = 1 To Columns.Count 'Find the REAL bottom row
        If Cells(Rows.Count, Col).End(xlUp).Row > BottomRow Then
            BottomRow = Cells(Rows.Count, Col).End(xlUp).Row
        End If
    Next
    'Find the end cell of data on each row that has data and find the furthest one
    For R = 1 To BottomRow 'Find the REAL most right column
        If Cells(R, Columns.Count).End(xlToLeft).Column > EndCol Then
            EndCol = Cells(R, Columns.Count).End(xlToLeft).Column
        End If
    Next
    'Copy the REAL set of data
    Range(Cells(1, 1), Cells(BottomRow, EndCol)).Copy
    Sheets(CurrentSheet).Activate
    'Paste everything
    Range("A1").PasteSpecial xlPasteAll
    'Paste Column Widths
    Range("A1").PasteSpecial xlPasteColumnWidths
    'Begin addition 6/4/2010 for request: http://www.mrexcel.com/forum/showthread.php?p=2269274#post2269274
    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
    'End Addition 6/4/2010 for request: http://www.mrexcel.com/forum/showthread.php?p=2269274#post2269274
    'Reset the variable for the next sheet
    BottomRow = 0
    EndCol = 0
Next
'Excel will automatically replace the sheet references for you on your formulas, the below part puts them back
'This is done with a simple reaplce, replacing TRMFAT with nothing
For Each WS In Worksheets
    WS.Activate
    Cells.Replace "TRMFAT", ""
Next
'Poll through the sheets and delete the original bloated sheets
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
 
Upvote 0
Thanks for the code help!

Unfortunately, it froze Excel both times I attempting to run the macro. I don't know what happened but it's ok, your first code worked, I just have to add the pics after it runs.
 
Upvote 0
That is most strange.

Could you just run this for me and let me know what it does?

Code:
Sub PicNames
    For Each Pic In ActiveSheet.Pictures
        msgbox Pic.name
    Next
End sub
 
Upvote 0
It froze me out without any of the macro running. Your first code ran fine and adding in the company logo is simple enough afterwards.
 
Upvote 0

Forum statistics

Threads
1,215,330
Messages
6,124,305
Members
449,150
Latest member
NyDarR

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top