Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default how can hide and show columns using macro?

How can I unhide hidden columns and then hide them again by macro? suppose
that I have a workbook made of 10 columns. colum 3,4 and 5 are hidden by
default. I want to unhide these hidden columns when I type word "AB" in any
cell in colum Number 1. and then by pressing enter I want to hide these
columns again. is this possible using macro?

Many thanks
Hoshyar
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default how can hide and show columns using macro?

macros don't run while you are editing a cell, so if you mean hit Enter to
exit edit mode, then no.

--
Regards,
Tom Ogilvy


"Hoshyar" wrote in message
...
How can I unhide hidden columns and then hide them again by macro? suppose
that I have a workbook made of 10 columns. colum 3,4 and 5 are hidden by
default. I want to unhide these hidden columns when I type word "AB" in

any
cell in colum Number 1. and then by pressing enter I want to hide these
columns again. is this possible using macro?

Many thanks
Hoshyar



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default how can hide and show columns using macro?

Many thanks for you answer Tom. But isn't it possible to unhide the hidden
columns by typing a word in another column?
In fact, once I did it with help of a freind, but I lost this workbook, and
now I am trying to do it again.

your answer is appreciated
Hoshyar


"Tom Ogilvy" wrote:

macros don't run while you are editing a cell, so if you mean hit Enter to
exit edit mode, then no.

--
Regards,
Tom Ogilvy


"Hoshyar" wrote in message
...
How can I unhide hidden columns and then hide them again by macro? suppose
that I have a workbook made of 10 columns. colum 3,4 and 5 are hidden by
default. I want to unhide these hidden columns when I type word "AB" in

any
cell in colum Number 1. and then by pressing enter I want to hide these
columns again. is this possible using macro?

Many thanks
Hoshyar




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default how can hide and show columns using macro?

Hi Hoshyar

It is not possible to undide and then hide the column while you are editing
the cell. However, if you are wanting to toggle the unhide/hide each time you
type AB in column A you can achieve this with a change event macro:

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrorHandler
Application.EnableEvents = False
If Target.Column = 1 And Target.Count = 1 Then
If Target.Value = "AB" Then
If Columns("C:E").Hidden Then
Columns("C:E").Hidden = False
Else
Columns("C:E").Hidden = True
End If
End If
End If
ErrorHandler:
Application.EnableEvents = True
End Sub

This is worksheet event code. Right click the sheet tab, select view code
and paste the code in there.

As Tom has said this will not run while you are editing the cell but rather
once the change is made. So each time you type AB in column A, columns C:E
will be hidden/unhidden.

Hope this helps
Rowan

"Hoshyar" wrote:

Many thanks for you answer Tom. But isn't it possible to unhide the hidden
columns by typing a word in another column?
In fact, once I did it with help of a freind, but I lost this workbook, and
now I am trying to do it again.

your answer is appreciated
Hoshyar


"Tom Ogilvy" wrote:

macros don't run while you are editing a cell, so if you mean hit Enter to
exit edit mode, then no.

--
Regards,
Tom Ogilvy


"Hoshyar" wrote in message
...
How can I unhide hidden columns and then hide them again by macro? suppose
that I have a workbook made of 10 columns. colum 3,4 and 5 are hidden by
default. I want to unhide these hidden columns when I type word "AB" in

any
cell in colum Number 1. and then by pressing enter I want to hide these
columns again. is this possible using macro?

Many thanks
Hoshyar




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default how can hide and show columns using macro?

Hi Rowan,

If Columns("C:E").Hidden Then
Columns("C:E").Hidden = False
Else
Columns("C:E").Hidden = True
End If


could also be expressed as:

Columns("C:E").Hidden = Not Columns("C:E").Hidden

---
Regards,
Norman



"Rowan" <rowanzsa at hotmailNOSPAM dot com wrote in message
...
Hi Hoshyar

It is not possible to undide and then hide the column while you are
editing
the cell. However, if you are wanting to toggle the unhide/hide each time
you
type AB in column A you can achieve this with a change event macro:

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrorHandler
Application.EnableEvents = False
If Target.Column = 1 And Target.Count = 1 Then
If Target.Value = "AB" Then
If Columns("C:E").Hidden Then
Columns("C:E").Hidden = False
Else
Columns("C:E").Hidden = True
End If
End If
End If
ErrorHandler:
Application.EnableEvents = True
End Sub

This is worksheet event code. Right click the sheet tab, select view code
and paste the code in there.

As Tom has said this will not run while you are editing the cell but
rather
once the change is made. So each time you type AB in column A, columns C:E
will be hidden/unhidden.

Hope this helps
Rowan

"Hoshyar" wrote:

Many thanks for you answer Tom. But isn't it possible to unhide the
hidden
columns by typing a word in another column?
In fact, once I did it with help of a freind, but I lost this workbook,
and
now I am trying to do it again.

your answer is appreciated
Hoshyar


"Tom Ogilvy" wrote:

macros don't run while you are editing a cell, so if you mean hit Enter
to
exit edit mode, then no.

--
Regards,
Tom Ogilvy


"Hoshyar" wrote in message
...
How can I unhide hidden columns and then hide them again by macro?
suppose
that I have a workbook made of 10 columns. colum 3,4 and 5 are hidden
by
default. I want to unhide these hidden columns when I type word "AB"
in
any
cell in colum Number 1. and then by pressing enter I want to hide
these
columns again. is this possible using macro?

Many thanks
Hoshyar







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default how can hide and show columns using macro?

Thanks Norman

I knew there was a better way but my brain stopped working and totally
forgot about "Not" in relation to boolean values. <g

Regards
Rowan

"Norman Jones" wrote:

Hi Rowan,

If Columns("C:E").Hidden Then
Columns("C:E").Hidden = False
Else
Columns("C:E").Hidden = True
End If


could also be expressed as:

Columns("C:E").Hidden = Not Columns("C:E").Hidden

---
Regards,
Norman



"Rowan" <rowanzsa at hotmailNOSPAM dot com wrote in message
...
Hi Hoshyar

It is not possible to undide and then hide the column while you are
editing
the cell. However, if you are wanting to toggle the unhide/hide each time
you
type AB in column A you can achieve this with a change event macro:

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrorHandler
Application.EnableEvents = False
If Target.Column = 1 And Target.Count = 1 Then
If Target.Value = "AB" Then
If Columns("C:E").Hidden Then
Columns("C:E").Hidden = False
Else
Columns("C:E").Hidden = True
End If
End If
End If
ErrorHandler:
Application.EnableEvents = True
End Sub

This is worksheet event code. Right click the sheet tab, select view code
and paste the code in there.

As Tom has said this will not run while you are editing the cell but
rather
once the change is made. So each time you type AB in column A, columns C:E
will be hidden/unhidden.

Hope this helps
Rowan

"Hoshyar" wrote:

Many thanks for you answer Tom. But isn't it possible to unhide the
hidden
columns by typing a word in another column?
In fact, once I did it with help of a freind, but I lost this workbook,
and
now I am trying to do it again.

your answer is appreciated
Hoshyar


"Tom Ogilvy" wrote:

macros don't run while you are editing a cell, so if you mean hit Enter
to
exit edit mode, then no.

--
Regards,
Tom Ogilvy


"Hoshyar" wrote in message
...
How can I unhide hidden columns and then hide them again by macro?
suppose
that I have a workbook made of 10 columns. colum 3,4 and 5 are hidden
by
default. I want to unhide these hidden columns when I type word "AB"
in
any
cell in colum Number 1. and then by pressing enter I want to hide
these
columns again. is this possible using macro?

Many thanks
Hoshyar






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
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
Show / Hide Columns in multiple sheets Shadster Excel Programming 2 June 27th 05 12:09 PM
Show/Hide Columns StephanieH Excel Programming 8 June 24th 05 02:16 PM
Macro to Hide/Show Columns based on control cell value Steve N Excel Programming 2 May 25th 04 06:51 PM


All times are GMT +1. The time now is 08:03 PM.

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

About Us

"It's about Microsoft Excel"