Link to home
Start Free TrialLog in
Avatar of Nick
Nick

asked on

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
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Why do you need VBA? Just hide the unused rows and columns, that's it.
Avatar of Nick
Nick

ASKER

ok, how can I do it with VBA?
Avatar of Nick

ASKER

VBA because I have another bigger project in mind, and by doing this one I learn from your solutions.
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

Avatar of Nick

ASKER

Sorry for another silly question: how do I call this sub on a sheet loading or activation?
ASKER CERTIFIED SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
Avatar of Nick

ASKER

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.
Avatar of Nick

ASKER

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
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.