PC Review


Reply
Thread Tools Rate Thread

Call sub from worksheet_change

 
 
JMJ
Guest
Posts: n/a
 
      4th May 2008
Hi all,
I've been wrestling with this and I cannot see where I have the error. For
some reason it does not call the macro: "Validate". Any help would be greatly
appreciated.

I have the following code in Sheet 1

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ws_exit
Application.EnableEvents = False
Application.ScreenUpdating = True
If Not Application.Intersect(Target, Range("F14")) Is Nothing Then
With Target
If .Value <> "" Then

Validate

Else ' do other..
End If
End With
End If

Exit Sub
ws_exit:
Application.EnableEvents = True
Application.ScreenUpdating = True
MsgBox "Error ...."
End Sub
------------------------
In Module1 I have the code to validate cell B8.

Sub Validate()
With Range("B8").Validation
.Delete
.Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="=A1", Formula2:="=A5"
.IgnoreBlank = True
.InCellDropdown = True
End With
End Sub
----------------------
Thanks in advance for any help you can give me.


 
Reply With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      4th May 2008
You need:

Application.EnableEvents = True
Application.ScreenUpdating = True

before exiting ( you are currently executing them only on error)
--
Gary''s Student - gsnu200783


"JMJ" wrote:

> Hi all,
> I've been wrestling with this and I cannot see where I have the error. For
> some reason it does not call the macro: "Validate". Any help would be greatly
> appreciated.
>
> I have the following code in Sheet 1
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> On Error GoTo ws_exit
> Application.EnableEvents = False
> Application.ScreenUpdating = True
> If Not Application.Intersect(Target, Range("F14")) Is Nothing Then
> With Target
> If .Value <> "" Then
>
> Validate
>
> Else ' do other..
> End If
> End With
> End If
>
> Exit Sub
> ws_exit:
> Application.EnableEvents = True
> Application.ScreenUpdating = True
> MsgBox "Error ...."
> End Sub
> ------------------------
> In Module1 I have the code to validate cell B8.
>
> Sub Validate()
> With Range("B8").Validation
> .Delete
> .Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop, _
> Operator:=xlBetween, Formula1:="=A1", Formula2:="=A5"
> .IgnoreBlank = True
> .InCellDropdown = True
> End With
> End Sub
> ----------------------
> Thanks in advance for any help you can give me.
>
>

 
Reply With Quote
 
JMJ
Guest
Posts: n/a
 
      4th May 2008
It still doesn't call it. ...

"Gary''s Student" wrote:

> You need:
>
> Application.EnableEvents = True
> Application.ScreenUpdating = True
>
> before exiting ( you are currently executing them only on error)
> --
> Gary''s Student - gsnu200783
>
>
> "JMJ" wrote:
>
> > Hi all,
> > I've been wrestling with this and I cannot see where I have the error. For
> > some reason it does not call the macro: "Validate". Any help would be greatly
> > appreciated.
> >
> > I have the following code in Sheet 1
> >
> > Private Sub Worksheet_Change(ByVal Target As Range)
> > On Error GoTo ws_exit
> > Application.EnableEvents = False
> > Application.ScreenUpdating = True
> > If Not Application.Intersect(Target, Range("F14")) Is Nothing Then
> > With Target
> > If .Value <> "" Then
> >
> > Validate
> >
> > Else ' do other..
> > End If
> > End With
> > End If
> >
> > Exit Sub
> > ws_exit:
> > Application.EnableEvents = True
> > Application.ScreenUpdating = True
> > MsgBox "Error ...."
> > End Sub
> > ------------------------
> > In Module1 I have the code to validate cell B8.
> >
> > Sub Validate()
> > With Range("B8").Validation
> > .Delete
> > .Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop, _
> > Operator:=xlBetween, Formula1:="=A1", Formula2:="=A5"
> > .IgnoreBlank = True
> > .InCellDropdown = True
> > End With
> > End Sub
> > ----------------------
> > Thanks in advance for any help you can give me.
> >
> >

 
Reply With Quote
 
Gary''s Student
Guest
Posts: n/a
 
      4th May 2008
First fix the event code
Next run something like:

Sub en()
Application.EnableEvents = True
End Sub

Then try the data entry
--
Gary''s Student - gsnu200783


"JMJ" wrote:

> It still doesn't call it. ...
>
> "Gary''s Student" wrote:
>
> > You need:
> >
> > Application.EnableEvents = True
> > Application.ScreenUpdating = True
> >
> > before exiting ( you are currently executing them only on error)
> > --
> > Gary''s Student - gsnu200783
> >
> >
> > "JMJ" wrote:
> >
> > > Hi all,
> > > I've been wrestling with this and I cannot see where I have the error. For
> > > some reason it does not call the macro: "Validate". Any help would be greatly
> > > appreciated.
> > >
> > > I have the following code in Sheet 1
> > >
> > > Private Sub Worksheet_Change(ByVal Target As Range)
> > > On Error GoTo ws_exit
> > > Application.EnableEvents = False
> > > Application.ScreenUpdating = True
> > > If Not Application.Intersect(Target, Range("F14")) Is Nothing Then
> > > With Target
> > > If .Value <> "" Then
> > >
> > > Validate
> > >
> > > Else ' do other..
> > > End If
> > > End With
> > > End If
> > >
> > > Exit Sub
> > > ws_exit:
> > > Application.EnableEvents = True
> > > Application.ScreenUpdating = True
> > > MsgBox "Error ...."
> > > End Sub
> > > ------------------------
> > > In Module1 I have the code to validate cell B8.
> > >
> > > Sub Validate()
> > > With Range("B8").Validation
> > > .Delete
> > > .Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop, _
> > > Operator:=xlBetween, Formula1:="=A1", Formula2:="=A5"
> > > .IgnoreBlank = True
> > > .InCellDropdown = True
> > > End With
> > > End Sub
> > > ----------------------
> > > Thanks in advance for any help you can give me.
> > >
> > >

 
Reply With Quote
 
JMJ
Guest
Posts: n/a
 
      4th May 2008

The events are enabled.


"Gary''s Student" wrote:

> First fix the event code
> Next run something like:
>
> Sub en()
> Application.EnableEvents = True
> End Sub
>
> Then try the data entry
> --
> Gary''s Student - gsnu200783
>
>
> "JMJ" wrote:
>
> > It still doesn't call it. ...
> >
> > "Gary''s Student" wrote:
> >
> > > You need:
> > >
> > > Application.EnableEvents = True
> > > Application.ScreenUpdating = True
> > >
> > > before exiting ( you are currently executing them only on error)
> > > --
> > > Gary''s Student - gsnu200783
> > >
> > >
> > > "JMJ" wrote:
> > >
> > > > Hi all,
> > > > I've been wrestling with this and I cannot see where I have the error. For
> > > > some reason it does not call the macro: "Validate". Any help would be greatly
> > > > appreciated.
> > > >
> > > > I have the following code in Sheet 1
> > > >
> > > > Private Sub Worksheet_Change(ByVal Target As Range)
> > > > On Error GoTo ws_exit
> > > > Application.EnableEvents = False
> > > > Application.ScreenUpdating = True
> > > > If Not Application.Intersect(Target, Range("F14")) Is Nothing Then
> > > > With Target
> > > > If .Value <> "" Then
> > > >
> > > > Validate
> > > >
> > > > Else ' do other..
> > > > End If
> > > > End With
> > > > End If
> > > >
> > > > Exit Sub
> > > > ws_exit:
> > > > Application.EnableEvents = True
> > > > Application.ScreenUpdating = True
> > > > MsgBox "Error ...."
> > > > End Sub
> > > > ------------------------
> > > > In Module1 I have the code to validate cell B8.
> > > >
> > > > Sub Validate()
> > > > With Range("B8").Validation
> > > > .Delete
> > > > .Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop, _
> > > > Operator:=xlBetween, Formula1:="=A1", Formula2:="=A5"
> > > > .IgnoreBlank = True
> > > > .InCellDropdown = True
> > > > End With
> > > > End Sub
> > > > ----------------------
> > > > Thanks in advance for any help you can give me.
> > > >
> > > >

 
Reply With Quote
 
Gary''s Student
Guest
Posts: n/a
 
      4th May 2008
This works for me:

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ws_exit
Application.EnableEvents = False
Application.ScreenUpdating = True
If Not Intersect(Target, Range("F14")) Is Nothing Then
With Target
If .Value <> "" Then
Call Validate
Else
End If
End With
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
Exit Sub

ws_exit:
Application.EnableEvents = True
Application.ScreenUpdating = True
MsgBox "Error ...."
End Sub

Note I changed about three lines.
--
Gary''s Student - gsnu200783


"JMJ" wrote:

>
> The events are enabled.
>
>
> "Gary''s Student" wrote:
>
> > First fix the event code
> > Next run something like:
> >
> > Sub en()
> > Application.EnableEvents = True
> > End Sub
> >
> > Then try the data entry
> > --
> > Gary''s Student - gsnu200783
> >
> >
> > "JMJ" wrote:
> >
> > > It still doesn't call it. ...
> > >
> > > "Gary''s Student" wrote:
> > >
> > > > You need:
> > > >
> > > > Application.EnableEvents = True
> > > > Application.ScreenUpdating = True
> > > >
> > > > before exiting ( you are currently executing them only on error)
> > > > --
> > > > Gary''s Student - gsnu200783
> > > >
> > > >
> > > > "JMJ" wrote:
> > > >
> > > > > Hi all,
> > > > > I've been wrestling with this and I cannot see where I have the error. For
> > > > > some reason it does not call the macro: "Validate". Any help would be greatly
> > > > > appreciated.
> > > > >
> > > > > I have the following code in Sheet 1
> > > > >
> > > > > Private Sub Worksheet_Change(ByVal Target As Range)
> > > > > On Error GoTo ws_exit
> > > > > Application.EnableEvents = False
> > > > > Application.ScreenUpdating = True
> > > > > If Not Application.Intersect(Target, Range("F14")) Is Nothing Then
> > > > > With Target
> > > > > If .Value <> "" Then
> > > > >
> > > > > Validate
> > > > >
> > > > > Else ' do other..
> > > > > End If
> > > > > End With
> > > > > End If
> > > > >
> > > > > Exit Sub
> > > > > ws_exit:
> > > > > Application.EnableEvents = True
> > > > > Application.ScreenUpdating = True
> > > > > MsgBox "Error ...."
> > > > > End Sub
> > > > > ------------------------
> > > > > In Module1 I have the code to validate cell B8.
> > > > >
> > > > > Sub Validate()
> > > > > With Range("B8").Validation
> > > > > .Delete
> > > > > .Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop, _
> > > > > Operator:=xlBetween, Formula1:="=A1", Formula2:="=A5"
> > > > > .IgnoreBlank = True
> > > > > .InCellDropdown = True
> > > > > End With
> > > > > End Sub
> > > > > ----------------------
> > > > > Thanks in advance for any help you can give me.
> > > > >
> > > > >

 
Reply With Quote
 
JMJ
Guest
Posts: n/a
 
      4th May 2008
Thanks!

For some reason it did not like the "Application.Intersect" (?) ...

Correction: At the beginning of the sub I have an
Application.ScreenUpdating = True
and it should be an "Application.ScreenUpdating = False"

"Gary''s Student" wrote:

> This works for me:
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> On Error GoTo ws_exit
> Application.EnableEvents = False
> Application.ScreenUpdating = True
> If Not Intersect(Target, Range("F14")) Is Nothing Then
> With Target
> If .Value <> "" Then
> Call Validate
> Else
> End If
> End With
> End If
> Application.EnableEvents = True
> Application.ScreenUpdating = True
> Exit Sub
>
> ws_exit:
> Application.EnableEvents = True
> Application.ScreenUpdating = True
> MsgBox "Error ...."
> End Sub
>
> Note I changed about three lines.
> --
> Gary''s Student - gsnu200783
>
>
> "JMJ" wrote:
>
> >
> > The events are enabled.
> >
> >
> > "Gary''s Student" wrote:
> >
> > > First fix the event code
> > > Next run something like:
> > >
> > > Sub en()
> > > Application.EnableEvents = True
> > > End Sub
> > >
> > > Then try the data entry
> > > --
> > > Gary''s Student - gsnu200783
> > >
> > >
> > > "JMJ" wrote:
> > >
> > > > It still doesn't call it. ...
> > > >
> > > > "Gary''s Student" wrote:
> > > >
> > > > > You need:
> > > > >
> > > > > Application.EnableEvents = True
> > > > > Application.ScreenUpdating = True
> > > > >
> > > > > before exiting ( you are currently executing them only on error)
> > > > > --
> > > > > Gary''s Student - gsnu200783
> > > > >
> > > > >
> > > > > "JMJ" wrote:
> > > > >
> > > > > > Hi all,
> > > > > > I've been wrestling with this and I cannot see where I have the error. For
> > > > > > some reason it does not call the macro: "Validate". Any help would be greatly
> > > > > > appreciated.
> > > > > >
> > > > > > I have the following code in Sheet 1
> > > > > >
> > > > > > Private Sub Worksheet_Change(ByVal Target As Range)
> > > > > > On Error GoTo ws_exit
> > > > > > Application.EnableEvents = False
> > > > > > Application.ScreenUpdating = True
> > > > > > If Not Application.Intersect(Target, Range("F14")) Is Nothing Then
> > > > > > With Target
> > > > > > If .Value <> "" Then
> > > > > >
> > > > > > Validate
> > > > > >
> > > > > > Else ' do other..
> > > > > > End If
> > > > > > End With
> > > > > > End If
> > > > > >
> > > > > > Exit Sub
> > > > > > ws_exit:
> > > > > > Application.EnableEvents = True
> > > > > > Application.ScreenUpdating = True
> > > > > > MsgBox "Error ...."
> > > > > > End Sub
> > > > > > ------------------------
> > > > > > In Module1 I have the code to validate cell B8.
> > > > > >
> > > > > > Sub Validate()
> > > > > > With Range("B8").Validation
> > > > > > .Delete
> > > > > > .Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop, _
> > > > > > Operator:=xlBetween, Formula1:="=A1", Formula2:="=A5"
> > > > > > .IgnoreBlank = True
> > > > > > .InCellDropdown = True
> > > > > > End With
> > > > > > End Sub
> > > > > > ----------------------
> > > > > > Thanks in advance for any help you can give me.
> > > > > >
> > > > > >

 
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
Can Worksheet_Change call itself? Brad E. Microsoft Excel Programming 6 24th Feb 2009 02:44 PM
RE: Can Worksheet_Change call itself? Brad E. Microsoft Excel Programming 0 17th Feb 2009 08:01 PM
RE: Can Worksheet_Change call itself? Mike H Microsoft Excel Programming 0 17th Feb 2009 07:49 PM
Combine 2 codes from WorkSheet_Change & WorkSheet _SelectionChange to ONLY WorkSheet_Change Corey Microsoft Excel Programming 2 17th Dec 2006 09:59 PM
Call Worksheet_Change macro in another worksheet =?Utf-8?B?RnJlZGR5?= Microsoft Excel Programming 6 29th Oct 2006 07:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:09 PM.