Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA column hiding


hello,

does anybody know of a macro of sorts that will check to see if
column is populated and if not to automatically hide it?
Essentially I have 15 columns of which only 8 may have data and I woul
like to hide the remaining columns at one time....

Thanks a lot

--
natijo
-----------------------------------------------------------------------
natijoe's Profile: http://www.excelforum.com/member.php...fo&userid=2555
View this thread: http://www.excelforum.com/showthread.php?threadid=39002

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default VBA column hiding

Hi Natijoe,

Try:

Sub Tester01()
Dim rng As Range
Dim col As Range
Dim sh As Worksheet

Set sh = ActiveSheet '<<===== CHANGE

For Each col In sh.UsedRange
Set rng = col.Cells
col.EntireColumn.Hidden = Application.CountA(rng) = 0
Next col

End Sub


---
Regards,
Norman



"natijoe" wrote in
message ...

hello,

does anybody know of a macro of sorts that will check to see if a
column is populated and if not to automatically hide it?
Essentially I have 15 columns of which only 8 may have data and I would
like to hide the remaining columns at one time....

Thanks a lot!


--
natijoe
------------------------------------------------------------------------
natijoe's Profile:
http://www.excelforum.com/member.php...o&userid=25556
View this thread: http://www.excelforum.com/showthread...hreadid=390024



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default VBA column hiding

Sub HideColums()
Dim i As Long

For i = 1 To 15
If Application.CountA(Columns(i)) = 0 Then
Columns(i).Hidden = True
End If
Next i

End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"natijoe" wrote in
message ...

hello,

does anybody know of a macro of sorts that will check to see if a
column is populated and if not to automatically hide it?
Essentially I have 15 columns of which only 8 may have data and I would
like to hide the remaining columns at one time....

Thanks a lot!


--
natijoe
------------------------------------------------------------------------
natijoe's Profile:

http://www.excelforum.com/member.php...o&userid=25556
View this thread: http://www.excelforum.com/showthread...hreadid=390024



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default VBA column hiding

Hi Natijoe,

Or, more simply:

Sub Tester01()
Dim col As Range
Dim sh As Worksheet

Set sh = ActiveSheet '<<===== CHANGE

For Each col In sh.UsedRange
col.EntireColumn.Hidden = Application.CountA(col) = 0
Next col

End Sub


---
Regards,
Norman



"natijoe" wrote in
message ...

hello,

does anybody know of a macro of sorts that will check to see if a
column is populated and if not to automatically hide it?
Essentially I have 15 columns of which only 8 may have data and I would
like to hide the remaining columns at one time....

Thanks a lot!


--
natijoe
------------------------------------------------------------------------
natijoe's Profile:
http://www.excelforum.com/member.php...o&userid=25556
View this thread: http://www.excelforum.com/showthread...hreadid=390024



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default VBA column hiding


For Each col In sh.UsedRange


Should have been:

For Each col In sh.UsedRange.Columns

to avoid unnecessary iteration.

---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Natijoe,

Or, more simply:

Sub Tester01()
Dim col As Range
Dim sh As Worksheet

Set sh = ActiveSheet '<<===== CHANGE

For Each col In sh.UsedRange
col.EntireColumn.Hidden = Application.CountA(col) = 0
Next col

End Sub


---
Regards,
Norman



"natijoe" wrote in
message ...

hello,

does anybody know of a macro of sorts that will check to see if a
column is populated and if not to automatically hide it?
Essentially I have 15 columns of which only 8 may have data and I would
like to hide the remaining columns at one time....

Thanks a lot!


--
natijoe
------------------------------------------------------------------------
natijoe's Profile:
http://www.excelforum.com/member.php...o&userid=25556
View this thread:
http://www.excelforum.com/showthread...hreadid=390024





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hiding a column of hyperlinks behind a column of numbers cmiling New Users to Excel 2 November 20th 09 05:02 PM
Hiding Column Issue Amy Excel Worksheet Functions 1 May 19th 09 04:36 PM
Column Hiding Eduardo Excel Discussion (Misc queries) 0 February 25th 09 07:51 PM
HIDING A COLUMN chris morr Excel Discussion (Misc queries) 0 March 29th 07 03:12 PM
hiding column using VB associates Excel Worksheet Functions 5 June 5th 06 09:10 AM


All times are GMT +1. The time now is 04:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"