PDA

View Full Version : [SOLVED:] vba cell event change & call macro combination



DeanP
12-12-2018, 12:28 PM
I need to run a macro that will unhide certain hidden columns when the active cell is no longer the active cell (users will click out of the active cell to deactivate it).

I think I have found snippets of code for the 3 events:

(a) unhide columns
Columns("A:G") .EntireColumn.Hidden = False I've called this macro ShowConsole

(b) active cell not active cell
If ActiveCell.Address<>"$M$16" Then and

(c) event change
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.Range("M16")) Is Nothing Then
Application.EnableEvents = False
Call ShowConsole
Application.EnableEvents = True
End If
End Sub

My problem is that I don't know how to bring all of this together.

mikerickson
12-12-2018, 03:00 PM
If you want code that will hide columns A:G when M13 is selected and unhide them when it is de-selected. Code like this in the sheet's code module should work.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Me.Range("A:G").EntireColumn.Hidden = (Target.Address = "$M$16")
End Sub

DeanP
12-16-2018, 11:08 AM
Thank you