Followers

Thursday, February 5, 2009

WAY TO REDUCED SIZE OF MS EXCEL FILE (MEMPERKECIL UKURAN FILE MS EXCEL)

one thing I've run across is that you often have a lot of space stored in a worksheet that you didn't even know was there.

Hit your home key and it should take you to the top of your worksheet (if this does not happen you need to go into your Tools - Options - Transition and enable lotus 1-2-3 transition navigation keys)

Then hit your End key followed by your Home key. This should take you to the lower right most cell of you worksheet.

If it takes you well below where you need to be, you're storing a lot of blank space.

Do a board search for "Bloat".

A common "noob" mistake (per your last post is to format an entire row or column when you're actually only using a small portion of those ranges.

That can take up more real estate than a Southern California Developer!

First step is to delete unused rows and columns. You can see a Mb file drop to Kb doing that.

If it's a distributable workbook, you can reduce file size with something like this:

Sub ReduceMe()
****Dim ws As Worksheet
********
********With Application
************.ScreenUpdating = False
************
************For Each ws In ActiveWorkbook.Worksheets
****************ws.Activate
********************With Cells
************************.Copy
************************.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
****************************:=False, Transpose:=False
********************End With
************Next ws
****************
************.CutCopyMode = False
************.ScreenUpdating = True
********End With
********
End Sub


Macros do add to file size on an incremental basis, so you don't want to have a bunch of empty modules/garbage lying around. Note that recorder adds a bunch of extraneous stuff that you don't need, so you'll also want to clean them up. Post code here to have the pundits do it for you

"Cells" is the same as doing CTRL+A (Select All). To see it in action, record a macro on any sheet and perform the following keystrokes-->CTRL+A-->CTRL+C-->/ESV-->ESC (Escape key).

You'll get this

Option Explicit
'** Option Explicit keeps you honest and will make you
'** write your code more efficiently
'** See Dimensioning Variables in the Helpfile

Sub Macro1()
****Cells.Select
****Selection.Copy
****Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
********False, Transpose:=False
****Range("A1").Select
****Application.CutCopyMode = False
End Sub

'** But you can do this much faster

'** There's generally no need to Select objects in order to work with them
'** Where you see Select followed by Selection, you can
'** generally**remove both statements
'** Selecting can really slow you down; not selecting forces VBA to
'** do your work in the background
'** Anytime VBA sees a period (.) it has to calculate that step
'** With statements and removing Selects helps speed it up
'** by removing periods incrementally

'** Run both Macros and see if there's a difference
'** Although in this code there won't be much difference

Sub Macro2()
****'** With statements can be nested
****With Application
********'** Turn off "Screen Flashing/Movement"
********.ScreenUpdating = False
********
********'** Cells = Apply to the entire worksheet
********With Cells
************.Copy
************.PasteSpecial Paste:=xlValues
********End With
********
********'** Goto instead of Selecting
********.Goto [A1]
********'** Turn off the "Moving Copy Border"
********.CutCopyMode = False
********.ScreenUpdating = True
********'** Microsoft used to automatically set this back to True,
********'** but aparrently won't support it in the future, so make sure that
********'** you do
****End With
****
End Sub


Reference :

http://www.mrexcel.com/forum/showthread.php?t=97014




0 comments

Post a Comment