VBA way to remove unused cells and raws from Excel

Experts, I am looking for VBA solution to remove all unused cells and raws from excell the only sheet.
code.xlsm
NickAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Why do you need VBA? Just hide the unused rows and columns, that's it.
0
NickAuthor Commented:
ok, how can I do it with VBA?
0
NickAuthor Commented:
VBA because I have another bigger project in mind, and by doing this one I learn from your solutions.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Based on your file, simply try this...
Place the following code on a Standard Module like Module1.

Sub HideRowsAndColumns()
Columns("C:XFD").Hidden = True
Rows("13:1048576").Hidden = True
End Sub

Open in new window

0
NickAuthor Commented:
Sorry for another silly question: how do I call this sub on a sheet loading or activation?
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
If you mean you want to hide the rows and columns of Sheet1 while you open the file, place the following code on ThisWorkbook Module.
On VB Editor, in the project window, double click on ThisWorkbook and paste the following code into the opened code window.

Private Sub Workbook_Open()
With Sheets("Sheet1")
    .Columns("C:XFD").Hidden = True
    .Rows("13:1048576").Hidden = True
End With
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Martin LissOlder than dirtCommented:
Do you want to remove unused rows and columns or do you want to just hide them? Also as far as I can see, the workbook you posted has no data. Do you have a sample workbook that does have data?
0
NickAuthor Commented:
I would like to remove unused cells and columns so excel would look more like an application. Hiding does not give  it the right look.
0
NickAuthor Commented:
Subodh, not sure if I touched something but it shows me an error that it can not hide cells. I saw it working at least once.
code.xlsm
0
Martin LissOlder than dirtCommented:
I'm sure that Neeraj or I can provide you with a solution, but speaking for myself, I'd like you to close your previous questions before I supply a solution.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.