Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default Show/Hide Columns

I want my user to be able to show or hide several columns in my worksheet.
If they are already hidden, they should unhide and vice versa. The following
will unhide hidden columns, but will not hide unhidden columns. What am I
doing wrong?

Private Sub Detail_Click()
' Show/Hide Detail

If Columns("B:Y").Hidden = False Then
Columns("B:Y").Hidden = True
Range("a1").Activate
End If

If Columns("B:Y").Hidden = True Then
Columns("B:Y").Hidden = False
Range("a1").Activate
End If

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 233
Default Show/Hide Columns

Use EntireRow and EntireColumn

e.g. Range("B:Y").EntireColumn.Hidden = true

DM Unseen

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 221
Default Show/Hide Columns

Try this, Stephanie:

Sub Detail_Click()
' Show/Hide Detail

If Columns("B:C").Hidden = False Then
Columns("B:C").Hidden = True
Else
If Columns("B:C").Hidden = True Then
Columns("B:C").Hidden = False
Range("a1").Activate
End If
End If


End Sub
*******************
~Anne Troy

www.OfficeArticles.com
www.MyExpertsOnline.com


"StephanieH" wrote in message
...
I want my user to be able to show or hide several columns in my worksheet.
If they are already hidden, they should unhide and vice versa. The

following
will unhide hidden columns, but will not hide unhidden columns. What am I
doing wrong?

Private Sub Detail_Click()
' Show/Hide Detail

If Columns("B:Y").Hidden = False Then
Columns("B:Y").Hidden = True
Range("a1").Activate
End If

If Columns("B:Y").Hidden = True Then
Columns("B:Y").Hidden = False
Range("a1").Activate
End If

End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Show/Hide Columns

Your code first hides visible columns, then unhides invisible columns.
You could try an If...Then...Else...End If structu

Private Sub Detail_Click()
' Show/Hide Detail
If Columns("B:Y").Hidden = False Then
Columns("B:Y").Hidden = True
Else
Columns("B:Y").Hidden = False
End If
Range("a1").Activate
End Sub

or you could "toggle" between hidden and not hidden:

Private Sub Detail_Click()
' Show/Hide Detail
With Columns("B:V")
.Hidden = Not .Hidden
End With
End Sub



In article ,
"StephanieH" wrote:

I want my user to be able to show or hide several columns in my worksheet.
If they are already hidden, they should unhide and vice versa. The following
will unhide hidden columns, but will not hide unhidden columns. What am I
doing wrong?

Private Sub Detail_Click()
' Show/Hide Detail

If Columns("B:Y").Hidden = False Then
Columns("B:Y").Hidden = True
Range("a1").Activate
End If

If Columns("B:Y").Hidden = True Then
Columns("B:Y").Hidden = False
Range("a1").Activate
End If

End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 221
Default Show/Hide Columns

I'll just keep answering wrong and lame, and you just keep teaching me,
okay, JE? :)
This is only about the 4th or 5th question in the last 24 hours where I've
learned...
*******************
~Anne Troy

www.OfficeArticles.com
www.MyExpertsOnline.com


"JE McGimpsey" wrote in message
...
Your code first hides visible columns, then unhides invisible columns.
You could try an If...Then...Else...End If structu

Private Sub Detail_Click()
' Show/Hide Detail
If Columns("B:Y").Hidden = False Then
Columns("B:Y").Hidden = True
Else
Columns("B:Y").Hidden = False
End If
Range("a1").Activate
End Sub

or you could "toggle" between hidden and not hidden:

Private Sub Detail_Click()
' Show/Hide Detail
With Columns("B:V")
.Hidden = Not .Hidden
End With
End Sub



In article ,
"StephanieH" wrote:

I want my user to be able to show or hide several columns in my

worksheet.
If they are already hidden, they should unhide and vice versa. The

following
will unhide hidden columns, but will not hide unhidden columns. What am

I
doing wrong?

Private Sub Detail_Click()
' Show/Hide Detail

If Columns("B:Y").Hidden = False Then
Columns("B:Y").Hidden = True
Range("a1").Activate
End If

If Columns("B:Y").Hidden = True Then
Columns("B:Y").Hidden = False
Range("a1").Activate
End If

End Sub





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Show/Hide Columns

Columns("B:Y").Hidden = Not Columns("B:Y").Hidden

--
HTH

Bob Phillips

"StephanieH" wrote in message
...
I want my user to be able to show or hide several columns in my worksheet.
If they are already hidden, they should unhide and vice versa. The

following
will unhide hidden columns, but will not hide unhidden columns. What am I
doing wrong?

Private Sub Detail_Click()
' Show/Hide Detail

If Columns("B:Y").Hidden = False Then
Columns("B:Y").Hidden = True
Range("a1").Activate
End If

If Columns("B:Y").Hidden = True Then
Columns("B:Y").Hidden = False
Range("a1").Activate
End If

End Sub



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default Show/Hide Columns

Works perfectly. Thanks.

"Anne Troy" wrote:

Try this, Stephanie:

Sub Detail_Click()
' Show/Hide Detail

If Columns("B:C").Hidden = False Then
Columns("B:C").Hidden = True
Else
If Columns("B:C").Hidden = True Then
Columns("B:C").Hidden = False
Range("a1").Activate
End If
End If


End Sub
*******************
~Anne Troy

www.OfficeArticles.com
www.MyExpertsOnline.com


"StephanieH" wrote in message
...
I want my user to be able to show or hide several columns in my worksheet.
If they are already hidden, they should unhide and vice versa. The

following
will unhide hidden columns, but will not hide unhidden columns. What am I
doing wrong?

Private Sub Detail_Click()
' Show/Hide Detail

If Columns("B:Y").Hidden = False Then
Columns("B:Y").Hidden = True
Range("a1").Activate
End If

If Columns("B:Y").Hidden = True Then
Columns("B:Y").Hidden = False
Range("a1").Activate
End If

End Sub




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Show/Hide Columns

Well, first, your code wasn't wrong. It wasn't as efficient as mine, but
the primary consideration should be: does it work when you test it.

Second - posting your solutions is a *great* way to learn. There's
nothing like coming up with a workable answer and posting it, only to
find someone else has posted a different, perhaps more elegant answer
that you can compare it to and learn from. Happens to me all the time...

In article m,
"Anne Troy" wrote:

I'll just keep answering wrong and lame, and you just keep teaching me,
okay, JE? :)
This is only about the 4th or 5th question in the last 24 hours where I've
learned...

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 221
Default Show/Hide Columns

LOL, JE. I have perhaps 30,000 posts in forums "upstairs" (I always see the
newsgroups as some kind of basement. I dunno why!). There is no end to
learning. Now, if I could just figure out how to quit losing the threads
here in the newsgroups, I'd get a lot more posts down here!
:)
Thanks for teaching me!
*******************
~Anne Troy

www.OfficeArticles.com
www.MyExpertsOnline.com


"JE McGimpsey" wrote in message
...
Well, first, your code wasn't wrong. It wasn't as efficient as mine, but
the primary consideration should be: does it work when you test it.

Second - posting your solutions is a *great* way to learn. There's
nothing like coming up with a workable answer and posting it, only to
find someone else has posted a different, perhaps more elegant answer
that you can compare it to and learn from. Happens to me all the time...

In article m,
"Anne Troy" wrote:

I'll just keep answering wrong and lame, and you just keep teaching me,
okay, JE? :)
This is only about the 4th or 5th question in the last 24 hours where

I've
learned...



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
Is there a quick way to show selected columns (not using hide) Anhlyss Excel Discussion (Misc queries) 1 February 18th 10 07:52 PM
How to show columns/cells in sheet but hide them in print? Jeff Korn Excel Discussion (Misc queries) 8 May 25th 08 05:54 PM
Shortcut for hide/show detail in grouped columns/rows Corey Excel Discussion (Misc queries) 1 November 20th 07 12:06 AM
Macro to hide/show rows and columns Leo Excel Discussion (Misc queries) 4 May 23rd 06 05:25 PM
how can hide and show columns using macro? Hoshyar Excel Worksheet Functions 4 September 2nd 05 03:45 PM


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

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"