PC Review


Reply
Thread Tools Rate Thread

How do I automatically hide empty columns in Excel?

 
 
Ned Mains
Guest
Posts: n/a
 
      19th Jun 2008
I have a spreadsheet which is prepared each month with approximately 167
columns, importing data from our application's database. Each month, a large
number of the columns of the spreadsheet contain no data, so other than the
column heading row, there is no data in the column. However, all columns are
necessary, as there may be data for any given month.

Is there a way to set up the spreadsheet to automatically hide the columns
that contain NO data, so only those columns containing data appear (making
the spreadsheet more user friendly)?
 
Reply With Quote
 
 
 
 
ward376
Guest
Posts: n/a
 
      19th Jun 2008
You can use this code. It assumes that the header is in the first row,
the data starts in the second row and that you want all columns
evaluated.

'Gary's Student
Sub way()
Dim r As Range
Dim nLastRow As Long
Dim nLastColumn As Integer
Dim i As Integer
Dim HideIt As Boolean
Dim j As Long

Set r = ActiveSheet.UsedRange
nLastRow = r.Rows.Count + r.Row - 1
nLastColumn = r.Columns.Count + r.Column - 1

For i = 1 To nLastColumn
HideIt = True
For j = 2 To nLastRow
If Cells(j, i).Value <> "" Then
HideIt = False
End If
Next
If HideIt = True Then
Columns(i).EntireColumn.Hidden = True
End If
Next

End Sub

Cliff Edwards
 
Reply With Quote
 
Don
Guest
Posts: n/a
 
      19th Jun 2008
There are two other options

1) Using the Custom view option under view. You can setup a vew that is
user friendly but may hide a column that has data.

2) Using a macro to hide columns. You can do tools/macro/record new macro
and hid the cells you do not want the tools/macro/stop . The next time you
load , you can run the macro and the columns will hide

"Ned Mains" wrote:

> I have a spreadsheet which is prepared each month with approximately 167
> columns, importing data from our application's database. Each month, a large
> number of the columns of the spreadsheet contain no data, so other than the
> column heading row, there is no data in the column. However, all columns are
> necessary, as there may be data for any given month.
>
> Is there a way to set up the spreadsheet to automatically hide the columns
> that contain NO data, so only those columns containing data appear (making
> the spreadsheet more user friendly)?

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically hide a row if it is empty Vil Microsoft Excel Misc 1 19th Nov 2008 11:10 AM
Is there a way to automatically hide empty rows? =?Utf-8?B?Q2hyaXN0aW5l?= Microsoft Excel Worksheet Functions 1 12th Apr 2007 10:22 PM
Un hide non empty columns hamad.fatima@gmail.com Microsoft Excel Programming 2 7th Mar 2006 07:28 AM
URGENT!! Use macro button to hide empty columns and rows...HELP!!!! Hawk Microsoft Excel Programming 8 8th Jul 2005 10:38 PM
Automatically hide or delete empty rows after IF ? Lost! Microsoft Excel Programming 0 2nd Jun 2005 10:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:50 AM.