Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Event macro?

Is there a way to have a macro automatically run when
dates are entered in cell B1 thru D1?

Any help help would be awesome, thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Event macro?

One way:

Enter this in the worksheet code module (right-click on the worksheet
tab and choose View Code):

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count 1 Then Exit Sub
If Not Intersect(.Cells, Range("B1:D1")) Is Nothing Then _
If IsDate(.Value) Then _
MyMacro
End With
End Sub


In article ,
"Kent" wrote:

Is there a way to have a macro automatically run when
dates are entered in cell B1 thru D1?

Any help help would be awesome, thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Event macro?

Works very nice, but can the event be triggered when both
cells are changed? the macro is triggered when any cell
from range B1:D1 is entered with a date. I want the user
to be able to enter a time parameter.

Thanks for helping


-----Original Message-----
One way:

Enter this in the worksheet code module (right-click on

the worksheet
tab and choose View Code):

Private Sub Worksheet_Change(ByVal Target As

Excel.Range)
With Target
If .Count 1 Then Exit Sub
If Not Intersect(.Cells, Range("B1:D1")) Is

Nothing Then _
If IsDate(.Value) Then _
MyMacro
End With
End Sub


In article ,
"Kent" wrote:

Is there a way to have a macro automatically run when
dates are entered in cell B1 thru D1?

Any help help would be awesome, thanks.

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Event macro?

What do you mean by "both"? There are *three* cells in B1:D1...

Does it matter which is changed first? What if the user wants to use the
existing time with a new date?

It's always helpful to put list all the requirements at the beginning...


In article ,
"Kent" wrote:

Works very nice, but can the event be triggered when both
cells are changed? the macro is triggered when any cell
from range B1:D1 is entered with a date. I want the user
to be able to enter a time parameter.

  #5   Report Post  
Posted to microsoft.public.excel.programming
ijb ijb is offline
external usenet poster
 
Posts: 26
Default Event macro?

Have a look at Worksheet_SelectionChange event (right-click the worksheet in
the VB editor and select "view code")
This event triggers every time any cell is changed.
You can then interrogate the "target" range that excel provides to the
event. "Target" is the range of cells changed.

--
If I've mis-understood the question please tell me.

HTH

ijb

Remove nospam from my e-mail address to talk direct

Not MCSD, MVP, TLA, P&P, PCMCIA, etc just trying to help


"Kent" wrote in message
...
Is there a way to have a macro automatically run when
dates are entered in cell B1 thru D1?

Any help help would be awesome, thanks.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Event macro?

Kent,

Here's a barebones routine that waits for all three cells to change, then
runs your code:

Private Sub Worksheet_Change(ByVal Target As Range)
Static Date1 As Boolean, Date2 As Boolean, Date3 As Boolean
If Not Intersect(Range("B1"), Target) Is Nothing Then ' first cell
Date1 = True
End If
If Not Intersect(Range("C1"), Target) Is Nothing Then ' first cell
Date2 = True
End If
If Not Intersect(Range("D1"), Target) Is Nothing Then ' first cell
Date3 = True
End If

If Date1 = True And Date2 = True And Date3 = True Then
MsgBox "do your code here"
Date1 = False
Date2 = False
Date3 = False
End If
End Sub

The problem is that if the user wants to change only one or two, then go, it
won't go. And it fires when they're cleared (deleted) too. Should not a
button be used to run your code instead?
--
Earl Kiosterud
mvpearl omitthisword at verizon period net
-------------------------------------------

"Kent" wrote in message
...
Is there a way to have a macro automatically run when
dates are entered in cell B1 thru D1?

Any help help would be awesome, thanks.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Event Macro help Scott Excel Discussion (Misc queries) 3 March 22nd 10 07:19 PM
Event Macro running another macro inside K1KKKA Excel Discussion (Misc queries) 1 December 20th 06 08:21 PM
It seems to me that I need an event Macro, nick s Excel Worksheet Functions 8 November 28th 05 05:37 PM
'Event' macro George Gee New Users to Excel 18 August 27th 05 12:50 PM
Event macro David McRitchie[_2_] Excel Programming 2 July 16th 03 06:20 PM


All times are GMT +1. The time now is 05:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"