2 validation macros

M

MrRJ

Hi,
I have two different cells with different validation results. I would a
macro to run for each of them depending on my scenario. It works for cell
A14, but does not work for A16. Why? What is wrong with this picture?

Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If Target.Address = "$A$14" Then
Application.EnableEvents = False
Call selectedmacro_click
Application.EnableEvents = True
End If
Application.ScreenUpdating = True

End Sub
Private Sub selectedmacro_click()
Range("A:IV").EntireColumn.Hidden = False

For Each c In Range("B1:IV1")
If c <> 1 Then Columns(c.Column).Hidden = True
Next c

Range("A10").Select
End Sub
Private Sub Target()
Range("A:IV").EntireColumn.Hidden = False

For Each c In Range("B1:IV1")
If c <> 1 Then Columns(c.Column).Hidden = True
Next c

Range("A10").Select
End Sub

Private Sub Worksheet1_Change(ByVal Period As Range)
Application.ScreenUpdating = False
If Period.Address = "$A$16" Then
Application.EnableEvents = False
Call selectedmacro1_click
Application.EnableEvents = True
End If
Application.ScreenUpdating = True

End Sub
Private Sub selectedmacro1_click()
Range("A:IV").EntireColumn.Hidden = False

For Each c In Range("B5:IV5")
If c <> 1 Then Columns(c.Column).Hidden = True
Next c

Range("A10").Select
End Sub
Private Sub Period()
Range("A:IV").EntireColumn.Hidden = False

For Each c In Range("B5:IV5")
If c <> 1 Then Columns(c.Column).Hidden = True
Next c

Range("A10").Select
End Sub
 
P

Per Jessen

Hi

As you can only have one worksheet_change macro, you have to do it like
this:

Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If Target.Address = "$A$14" Then
Application.EnableEvents = False
Call selectedmacro_click
Application.EnableEvents = True
ElseIf Target.Address = "$A$16" Then
Application.EnableEvents = False
Call selectedmacro1_click
Application.EnableEvents = True
End If
Application.ScreenUpdating = True
End Sub

Regards,
Per
 
M

MrRJ

That is awesome. It works. Thanks Per

Per Jessen said:
Hi

As you can only have one worksheet_change macro, you have to do it like
this:

Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If Target.Address = "$A$14" Then
Application.EnableEvents = False
Call selectedmacro_click
Application.EnableEvents = True
ElseIf Target.Address = "$A$16" Then
Application.EnableEvents = False
Call selectedmacro1_click
Application.EnableEvents = True
End If
Application.ScreenUpdating = True
End Sub

Regards,
Per
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top