Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 504
Default How to run macro automatically from range of cells

Hi,
I'm trying to run a macro automatically as soon as I enter specific text in
any cell of column A.

I have managed to run following code which works fine but it activates
macro as soon as I click cell in column A.

But I like to activate macro only if I add text "PAID" in any cell of column
A. Could someone please help. Here's the code:

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Not Intersect(Target, Range("A1:A3000")) Is Nothing Then
Call OpenCalendar
End If
End Sub

Thanks in advance
Kevin
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default How to run macro automatically from range of cells

First, you wouldn't use the worksheet_selection change event.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
'one cell at a time!
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("a:a")) Is Nothing Then
Exit Sub
End If

If UCase(Target.Value) = UCase("PAID") Then
Call OpenCalendar
End If
End Sub

Kevin wrote:

Hi,
I'm trying to run a macro automatically as soon as I enter specific text in
any cell of column A.

I have managed to run following code which works fine but it activates
macro as soon as I click cell in column A.

But I like to activate macro only if I add text "PAID" in any cell of column
A. Could someone please help. Here's the code:

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Not Intersect(Target, Range("A1:A3000")) Is Nothing Then
Call OpenCalendar
End If
End Sub

Thanks in advance
Kevin


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 504
Default How to run macro automatically from range of cells

Hi Dave,
Thanks a Lot, that's perfect exactly what I wanted.
There is little more help needed please:

This macro I'm intending to run is to insert date as soon as I type "PAID"
in column A. That part is ok now.

But macro is programmed to insert Date in "Active Cell" means it overwrites
"PAID" wording with date.

My question is How can I add date next to the "PAID" column instead of
overwriting active cell. e.g. If I type "PAID" in Cell A1 it activates
calendar macro and once I select date from calendar it should add date in
Cell B1 and leave PAID wording intact.

Here's the macro code I'm using:

=====================================

Private Sub cmdClose_Click()
' Close the UserForm
Unload Me
End Sub

Private Sub UserForm_Initialize()
' Check if active cell contains a date. If 'yes' show
' same date on calendar. If 'no' show today's date.
If IsDate(ActiveCell.Value) Then
Calendar1.Value = DateValue(ActiveCell.Value)
Else
Calendar1.Value = Date
End If
End Sub

Private Sub Calendar1_Click()
' Transfer date selected on calendar to active cell
' and close UserForm.
ActiveCell.Value = Calendar1.Value
Unload Me
End Sub

===================================

Thanks once again,
Kevin


"Dave Peterson" wrote:

First, you wouldn't use the worksheet_selection change event.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
'one cell at a time!
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("a:a")) Is Nothing Then
Exit Sub
End If

If UCase(Target.Value) = UCase("PAID") Then
Call OpenCalendar
End If
End Sub

Kevin wrote:

Hi,
I'm trying to run a macro automatically as soon as I enter specific text in
any cell of column A.

I have managed to run following code which works fine but it activates
macro as soon as I click cell in column A.

But I like to activate macro only if I add text "PAID" in any cell of column
A. Could someone please help. Here's the code:

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Not Intersect(Target, Range("A1:A3000")) Is Nothing Then
Call OpenCalendar
End If
End Sub

Thanks in advance
Kevin


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default How to run macro automatically from range of cells

If you're typing Paid, then I'd use this:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
'one cell at a time!
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("a:a")) Is Nothing Then
Exit Sub
End If

If UCase(Target.Value) = UCase("PAID") Then
application.enableevents = false
with target.offset(0,1)
.numberformat = "mm/dd/yyyy"
.value = date
end with
End If
End Sub

=======
If you're using the userform to get the date, then keep the original
Worksheet_Change event and modify your userform procedu

Private Sub Calendar1_Click()
' Transfer date selected on calendar to active cell
' and close UserForm.
application.enableevents = false
with activecell.offset(0,1)
.numberformat = "mm/dd/yyyy"
.value = calendar1.value
end with
application.enableevents = true
Unload Me
End Sub

(Untested!)

The "application.enableevents = false" lines stop excel from firing that event
procedure when the code makes a change to the worksheet.


Kevin wrote:

Hi Dave,
Thanks a Lot, that's perfect exactly what I wanted.
There is little more help needed please:

This macro I'm intending to run is to insert date as soon as I type "PAID"
in column A. That part is ok now.

But macro is programmed to insert Date in "Active Cell" means it overwrites
"PAID" wording with date.

My question is How can I add date next to the "PAID" column instead of
overwriting active cell. e.g. If I type "PAID" in Cell A1 it activates
calendar macro and once I select date from calendar it should add date in
Cell B1 and leave PAID wording intact.

Here's the macro code I'm using:

=====================================

Private Sub cmdClose_Click()
' Close the UserForm
Unload Me
End Sub

Private Sub UserForm_Initialize()
' Check if active cell contains a date. If 'yes' show
' same date on calendar. If 'no' show today's date.
If IsDate(ActiveCell.Value) Then
Calendar1.Value = DateValue(ActiveCell.Value)
Else
Calendar1.Value = Date
End If
End Sub

Private Sub Calendar1_Click()
' Transfer date selected on calendar to active cell
' and close UserForm.
ActiveCell.Value = Calendar1.Value
Unload Me
End Sub

===================================

Thanks once again,
Kevin

"Dave Peterson" wrote:

First, you wouldn't use the worksheet_selection change event.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
'one cell at a time!
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("a:a")) Is Nothing Then
Exit Sub
End If

If UCase(Target.Value) = UCase("PAID") Then
Call OpenCalendar
End If
End Sub

Kevin wrote:

Hi,
I'm trying to run a macro automatically as soon as I enter specific text in
any cell of column A.

I have managed to run following code which works fine but it activates
macro as soon as I click cell in column A.

But I like to activate macro only if I add text "PAID" in any cell of column
A. Could someone please help. Here's the code:

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Not Intersect(Target, Range("A1:A3000")) Is Nothing Then
Call OpenCalendar
End If
End Sub

Thanks in advance
Kevin


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default How to run macro automatically from range of cells

I left out a line!!!

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
'one cell at a time!
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("a:a")) Is Nothing Then
Exit Sub
End If

If UCase(Target.Value) = UCase("PAID") Then
application.enableevents = false
with target.offset(0,1)
.numberformat = "mm/dd/yyyy"
.value = date
end with
application.enableevents = True '<--added this line!
End If
End Sub

Dave Peterson wrote:

If you're typing Paid, then I'd use this:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
'one cell at a time!
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("a:a")) Is Nothing Then
Exit Sub
End If

If UCase(Target.Value) = UCase("PAID") Then
application.enableevents = false
with target.offset(0,1)
.numberformat = "mm/dd/yyyy"
.value = date
end with
End If
End Sub

=======
If you're using the userform to get the date, then keep the original
Worksheet_Change event and modify your userform procedu

Private Sub Calendar1_Click()
' Transfer date selected on calendar to active cell
' and close UserForm.
application.enableevents = false
with activecell.offset(0,1)
.numberformat = "mm/dd/yyyy"
.value = calendar1.value
end with
application.enableevents = true
Unload Me
End Sub

(Untested!)

The "application.enableevents = false" lines stop excel from firing that event
procedure when the code makes a change to the worksheet.

Kevin wrote:

Hi Dave,
Thanks a Lot, that's perfect exactly what I wanted.
There is little more help needed please:

This macro I'm intending to run is to insert date as soon as I type "PAID"
in column A. That part is ok now.

But macro is programmed to insert Date in "Active Cell" means it overwrites
"PAID" wording with date.

My question is How can I add date next to the "PAID" column instead of
overwriting active cell. e.g. If I type "PAID" in Cell A1 it activates
calendar macro and once I select date from calendar it should add date in
Cell B1 and leave PAID wording intact.

Here's the macro code I'm using:

=====================================

Private Sub cmdClose_Click()
' Close the UserForm
Unload Me
End Sub

Private Sub UserForm_Initialize()
' Check if active cell contains a date. If 'yes' show
' same date on calendar. If 'no' show today's date.
If IsDate(ActiveCell.Value) Then
Calendar1.Value = DateValue(ActiveCell.Value)
Else
Calendar1.Value = Date
End If
End Sub

Private Sub Calendar1_Click()
' Transfer date selected on calendar to active cell
' and close UserForm.
ActiveCell.Value = Calendar1.Value
Unload Me
End Sub

===================================

Thanks once again,
Kevin

"Dave Peterson" wrote:

First, you wouldn't use the worksheet_selection change event.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
'one cell at a time!
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("a:a")) Is Nothing Then
Exit Sub
End If

If UCase(Target.Value) = UCase("PAID") Then
Call OpenCalendar
End If
End Sub

Kevin wrote:

Hi,
I'm trying to run a macro automatically as soon as I enter specific text in
any cell of column A.

I have managed to run following code which works fine but it activates
macro as soon as I click cell in column A.

But I like to activate macro only if I add text "PAID" in any cell of column
A. Could someone please help. Here's the code:

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Not Intersect(Target, Range("A1:A3000")) Is Nothing Then
Call OpenCalendar
End If
End Sub

Thanks in advance
Kevin

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 504
Default How to run macro automatically from range of cells

Thanks Dave,
I used "untested" version you sent and it works like a charm.
I really appreciate for helping out to solve this puzzle.
Cheers
Kevin,



"Dave Peterson" wrote:

I left out a line!!!

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
'one cell at a time!
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("a:a")) Is Nothing Then
Exit Sub
End If

If UCase(Target.Value) = UCase("PAID") Then
application.enableevents = false
with target.offset(0,1)
.numberformat = "mm/dd/yyyy"
.value = date
end with
application.enableevents = True '<--added this line!
End If
End Sub

Dave Peterson wrote:

If you're typing Paid, then I'd use this:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
'one cell at a time!
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("a:a")) Is Nothing Then
Exit Sub
End If

If UCase(Target.Value) = UCase("PAID") Then
application.enableevents = false
with target.offset(0,1)
.numberformat = "mm/dd/yyyy"
.value = date
end with
End If
End Sub

=======
If you're using the userform to get the date, then keep the original
Worksheet_Change event and modify your userform procedu

Private Sub Calendar1_Click()
' Transfer date selected on calendar to active cell
' and close UserForm.
application.enableevents = false
with activecell.offset(0,1)
.numberformat = "mm/dd/yyyy"
.value = calendar1.value
end with
application.enableevents = true
Unload Me
End Sub

(Untested!)

The "application.enableevents = false" lines stop excel from firing that event
procedure when the code makes a change to the worksheet.

Kevin wrote:

Hi Dave,
Thanks a Lot, that's perfect exactly what I wanted.
There is little more help needed please:

This macro I'm intending to run is to insert date as soon as I type "PAID"
in column A. That part is ok now.

But macro is programmed to insert Date in "Active Cell" means it overwrites
"PAID" wording with date.

My question is How can I add date next to the "PAID" column instead of
overwriting active cell. e.g. If I type "PAID" in Cell A1 it activates
calendar macro and once I select date from calendar it should add date in
Cell B1 and leave PAID wording intact.

Here's the macro code I'm using:

=====================================

Private Sub cmdClose_Click()
' Close the UserForm
Unload Me
End Sub

Private Sub UserForm_Initialize()
' Check if active cell contains a date. If 'yes' show
' same date on calendar. If 'no' show today's date.
If IsDate(ActiveCell.Value) Then
Calendar1.Value = DateValue(ActiveCell.Value)
Else
Calendar1.Value = Date
End If
End Sub

Private Sub Calendar1_Click()
' Transfer date selected on calendar to active cell
' and close UserForm.
ActiveCell.Value = Calendar1.Value
Unload Me
End Sub

===================================

Thanks once again,
Kevin

"Dave Peterson" wrote:

First, you wouldn't use the worksheet_selection change event.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
'one cell at a time!
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("a:a")) Is Nothing Then
Exit Sub
End If

If UCase(Target.Value) = UCase("PAID") Then
Call OpenCalendar
End If
End Sub

Kevin wrote:

Hi,
I'm trying to run a macro automatically as soon as I enter specific text in
any cell of column A.

I have managed to run following code which works fine but it activates
macro as soon as I click cell in column A.

But I like to activate macro only if I add text "PAID" in any cell of column
A. Could someone please help. Here's the code:

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Not Intersect(Target, Range("A1:A3000")) Is Nothing Then
Call OpenCalendar
End If
End Sub

Thanks in advance
Kevin

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,058
Default How to run macro automatically from range of cells

Use Change rather than SelectionChange
--
Gary''s Student - gsnu200750


"Kevin" wrote:

Hi,
I'm trying to run a macro automatically as soon as I enter specific text in
any cell of column A.

I have managed to run following code which works fine but it activates
macro as soon as I click cell in column A.

But I like to activate macro only if I add text "PAID" in any cell of column
A. Could someone please help. Here's the code:

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Not Intersect(Target, Range("A1:A3000")) Is Nothing Then
Call OpenCalendar
End If
End Sub

Thanks in advance
Kevin

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
Set range to block of cells in Macro Karen Excel Discussion (Misc queries) 2 May 16th 07 09:01 PM
Macro and a range of cells ME Excel Discussion (Misc queries) 6 May 10th 07 05:48 PM
Macro to hide blank cells in a range Dave Excel Discussion (Misc queries) 1 February 1st 06 11:55 PM
Automatically clear values from a range of selected cells John Davies Excel Discussion (Misc queries) 1 June 28th 05 04:42 PM
automatically fill in a range of cells Maarten Excel Discussion (Misc queries) 1 April 29th 05 11:14 AM


All times are GMT +1. The time now is 06:53 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"