#1   Report Post  
Adam
 
Posts: n/a
Default Hiding columns

Can I hide 5 consecutive columns (X to AA) depending on the content in
another cell (Hide if Y2=4, display otherwise) without using conditional
formatting. I tried and made everything white but then the comments remain.
Any ideas?

  #2   Report Post  
Jason Morin
 
Posts: n/a
Default

You'd have to use a worksheet_change event:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim HideRng As Range
Set HideRng = Me.[X:AA]
With Target
If .Address < "$Y$2" Then Exit Sub
If .Value = 4 Then
HideRng.EntireColumn.Hidden = True
End If
End With
End Sub

---
Right-click on the worksheet tab, click on "View Code",
and paste in the code above. Press ALT+Q to close the VBE.

HTH
Jason
Atlanta, GA

-----Original Message-----
Can I hide 5 consecutive columns (X to AA) depending on

the content in
another cell (Hide if Y2=4, display otherwise) without

using conditional
formatting. I tried and made everything white but then

the comments remain.
Any ideas?

.

  #3   Report Post  
Adam
 
Posts: n/a
Default

Thanks Jason,
To expand my qestion a bit.
A have a workbook with 12 sheets.
If I enter the value 4 in cell D4 on sheet 1 I would like to hide columns X
to AA in sheet 4-10. Note that the name of the sheets 4-10 may change.
Is it possible by entering this 4 into D4 it automatically hides those
desired columns?
I'm quite new at visual basic so I do not know where in the VBA editor I
should paste the code.

Thanks


"Jason Morin" skrev:

You'd have to use a worksheet_change event:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim HideRng As Range
Set HideRng = Me.[X:AA]
With Target
If .Address < "$Y$2" Then Exit Sub
If .Value = 4 Then
HideRng.EntireColumn.Hidden = True
End If
End With
End Sub

---
Right-click on the worksheet tab, click on "View Code",
and paste in the code above. Press ALT+Q to close the VBE.

HTH
Jason
Atlanta, GA

-----Original Message-----
Can I hide 5 consecutive columns (X to AA) depending on

the content in
another cell (Hide if Y2=4, display otherwise) without

using conditional
formatting. I tried and made everything white but then

the comments remain.
Any ideas?

.


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 columns automatically dave glynn Excel Discussion (Misc queries) 2 February 1st 05 06:36 PM
hiding columns automatically dave glynn Excel Discussion (Misc queries) 0 February 1st 05 06:15 PM
Hiding columns based on user/password jmatchus Excel Worksheet Functions 0 January 17th 05 06:49 PM
Columns in Excel will not allow user to click in them Kim Excel Discussion (Misc queries) 1 December 28th 04 06:37 PM
Counting the Contents of Two Columns Molochi Excel Discussion (Misc queries) 6 December 22nd 04 08:13 PM


All times are GMT +1. The time now is 07:56 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"