PC Review


Reply
Thread Tools Rate Thread

2 validation macros

 
 
MrRJ
Guest
Posts: n/a
 
      3rd Jun 2009
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
 
Reply With Quote
 
 
 
 
Per Jessen
Guest
Posts: n/a
 
      3rd Jun 2009
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

"MrRJ" <(E-Mail Removed)> skrev i meddelelsen
news:149576DD-55CC-4AC3-ADCB-(E-Mail Removed)...
> 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


 
Reply With Quote
 
MrRJ
Guest
Posts: n/a
 
      3rd Jun 2009
That is awesome. It works. Thanks Per

"Per Jessen" wrote:

> 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
>
> "MrRJ" <(E-Mail Removed)> skrev i meddelelsen
> news:149576DD-55CC-4AC3-ADCB-(E-Mail Removed)...
> > 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

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macros & Validation =?Utf-8?B?Sm9obiBDYWxkZXI=?= Microsoft Excel New Users 0 13th Jun 2006 02:48 AM
Data Validation & Macros Michael Link Microsoft Excel Misc 2 9th Mar 2005 05:32 PM
Re: Validation/Macros Tom Ogilvy Microsoft Excel Programming 1 15th Jan 2004 04:21 PM
Re: Validation/Macros Ron de Bruin Microsoft Excel Programming 1 15th Jan 2004 04:19 PM
Re: Validation/Macros Ron de Bruin Microsoft Excel Programming 0 15th Jan 2004 04:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:16 PM.