Hide all Unused Rows and Columns

Mister H

Well-known Member
Joined
Mar 6, 2002
Messages
1,507
Hi:

Is there a simple way to hide rows and columns? A lady in my office just asked me how to make only Columns A to J visible and only show 100 rows. She doesn't want the rest of the spreadsheet to show. I know how to manually hide columns and rows but it takes a while to drag down and select 64000 rows so I thoguht I would ask the question:

Does Excel have a feature that will automatically hide all unused rows and columns or is there a simple VBA code to do this?

Any suggestions???

THANKS,
Mark :biggrin:
 
Try moving your "Protect" line of code outside your IF Then statement. Put it between the two End If's.
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi jonmo1... ONCE AGAIN you have solved my problem.

THANKS a million.

Have an AWESOME day,
Mark :biggrin:
 
Upvote 0
One LAST Question regarding this???

Hi:

I thought this board had my problems solved but now I have discovered a new one. I tried copying my codes to the 8 different spreadsheets that I need it in. The codes work if I F8 through them but for some reason the Shortcuts (ctrl + h and ctrl +u) are NOT working.

Why is that?

Do I need to go into each spreadsheet and create new macros and then paste the code in? I as normal, am CONFUSED.

Thanks Again,
Mark
 
Upvote 0
You will need to add the shortcut key for each one of the sheet macros you added it to unless you just added the macro to the personal.xls.
 
Upvote 0
Hi Brian:

Thanks for the reply... Is there any easy way of doing this? The only method I know of is to:

Open the spreadsheet
Select Tools/Macro/Record New Macro
Name my Macro
Identify my shortcut
Stop Recording
Go into VBA and paste the code to the macro I just created.

Do you have a easier method. I was going to just put it in the Personal VBA Foder but these spreadsheets will be used in many different locations.

Here's hoping for a nice simple method...
Mark :biggrin:
 
Upvote 0
If you have it in each workbook already then you can just press alt+F8 and select the macro you wish to give a shortcut to and click the options button and assign it that way.
 
Upvote 0
THANKS Brian. That is exactly what I was looking for.

THANKS to you and the others for all your help.

Take Care,
Mark :) :)
 
Upvote 0
Hope someone is still monitoring this thread.

When I use the code it returns with err-Number 1004 and description "Unable to set the Hidden property of the Range class"

Using the following code in Excel 2010 Windows 7 at 64 bit

Code:
Range(Cells(1,74), Cells(Rows.Count, Columns.Count)).EntireColumn.Hidden = True

It intends to hide all columns to the right of column BV (number 74)

Thanks in advance
 
Upvote 0
Hi,

If you select the last row manualy and press control+shift+arrow down then right click hide and select last column and press control+shift+right arrow and right click hide you get your result quickly if last row and last column are easy to find.

For me it became such a habit to delete them (reduce the size of the file) and then hide them that I made a shortcut on this macro in my rebbon (and another to delete rows&columns as one to unhide all rows and columns)

Code:
Sub MacHideExtRowsAndCol()


'! Will hide borders, objects and formating (also conditional) of last columns & row if no alphanumeric data (put 0 in white to avoid)


ActiveWorkbook.ActiveSheet.Cells.Select
'Hide empty last rows
Dim i As Long
i = 1

Do While Application.WorksheetFunction.CountA(Selection) <> 0

Rows(i).EntireRow.Select
Range(Selection, Selection.End(xlDown)).Select

i = i + 1
Loop

Selection.EntireRow.Hidden = True


ActiveWorkbook.ActiveSheet.Cells.Select
'Hide empty last columns
Dim k As Long
k = 1

Do While Application.WorksheetFunction.CountA(Selection) <> 0

Columns(k).EntireColumn.Select
Range(Selection, Selection.End(xlToRight)).Select

k = k + 1
Loop

Selection.EntireColumn.Hidden = True



Range("A1").Select
End Sub

Note that you can delete before hiding by adding selection.delete before 2 statements: " selection.Entire.....hidden=true "
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,336
Messages
6,124,338
Members
449,155
Latest member
ravioli44

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