accordian columns

Z

Zewlsash

Hello,

I was working with someone's database at work. I was updating names.
I would add a new 'last name' into the first column, then when I hi
the right arrow a new column called 'first name' would suddenly open u
to the right of the last name column. After finishing a new row an
hitting [enter], the 'first name' column would disappear again. Ho
can I make columns do this? Thank you for any help.

E
 
B

Bob Phillips

Here is one way

'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "A:B"

On Error GoTo ws_exit:
Application.EnableEvents = False
With Target
If .Column = 1 Then
Columns(2).Hidden = False
Else
Columns(2).Hidden = True
End If
End With

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.




--
HTH

Bob Phillips

(replace somewhere in email address with googlemail if mailing direct)
 
J

JE McGimpsey

One way, using an event macro:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Columns(2).Hidden = Target.Column <> 1
End Sub


Put this in the worksheet code module (right-click the worksheet tab and
choose View Code).
 
Z

Zewlsash

Bob and JE,

Thank you both for the examples. They were helpful for me to see.

Ed :)
 
Top