General discussion

Locked

Excel VBA to hide a column & unhide it

By fhu ·
I have the following code to enable a hidden column(G) to be unhidden, should
a certain subcategory in a previous column(E) be chosen. I took that from an
online example. However what I am trying to achieve without success is the
following: I would like column(G) automatically to be hidden again, once the next cell in the next column has been moved to. Any help would be much appreciated.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 5 And Target.Value = "Locators" Then
Columns("G").Hidden = False
ElseIf Target.Column = 5 And Target.Value = "Detectors" Then
Columns("G").Hidden = False
ElseIf Target.Column = 5 And Target.Value = "Survey/Navigation Equip." Then
Columns("G").Hidden = False
ElseIf Target.Column = 5 And Target.Value = "Machinery" Then
Columns("G").Hidden = False
ElseIf Target.Column = 5 And Target.Value = "Medical Equip. Cap. Assets"
Then
Columns("G").Hidden = False
ElseIf Target.Column = 5 And Target.Value = "Weapons" Then
Columns("G").Hidden = False
ElseIf Target.Column = 5 And Target.Value = "Desktops" Then
Columns("G").Hidden = False
ElseIf Target.Column = 5 And Target.Value = "Laptops" Then
Columns("G").Hidden = False
ElseIf Target.Column = 5 And Target.Value = "Printers" Then
Columns("G").Hidden = False
ElseIf Target.Column = 5 And Target.Value = "Scanners" Then
Columns("G").Hidden = False
ElseIf Target.Column = 5 And Target.Value = "Digital Cameras" Then
Columns("G").Hidden = False
ElseIf Target.Column = 5 And Target.Value = "Radios" Then
Columns("G").Hidden = False
ElseIf Target.Column = 5 And Target.Value = "Sat Phones" Then
Columns("G").Hidden = False
ElseIf Target.Column = 5 And Target.Value = "Mobile Phones" Then
Columns("G").Hidden = False
ElseIf Target.Column = 5 And Target.Value = "Vehicles" Then
Columns("G").Hidden = False

End If
End Sub

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

hide a column in excel before printing

by pksalwan In reply to

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Worksheets("FacturaIva").Columns("F").Hidden = True
End Sub

Change FacturaIVA with the name of your worksheet and "F" with the column name

To have fun change the above with this new code:
Worksheets("FacturaIva").Columns("F").Hidden = Not Worksheets("FacturaIva").Columns("F").Hidden

(It simply reverts true to false and vice versa)

Back to Software Forum
2 total posts (Page 1 of 1)  

Software Forums