Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Trying to call a macro on selection of a cell in a range

Hi,

This might come across as a novice question, as I am in fact, a novice at
vba. I'm trying to call a macro if a specific cell in a range is selected.
This is what I've coded.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Start_Range As Range
Set Start_Range = Range("C2:C1001")
Dim End_Range As Range
Set End_Range = Range("D2:D1001")
If Target.Range = Start_Range or Target.Range = End_Range Then
frmCalendar.Show
End If

End Sub

However, I'm getting a Compile error stating Argument not optional.

Can anyone please guide me to code this correctly?

Thanks in advance.

Sam

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Trying to call a macro on selection of a cell in a range

Got a solution to this through another forum. This is what was suggested and
worked.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim my_Range As Range
Set my_Range = Intersect(Target, Range("C2:C1001,D2:D1001"))
If Not my_Range Is Nothing Then frmCalendar.Show
End Sub





"The Narcissist" wrote:

Hi,

This might come across as a novice question, as I am in fact, a novice at
vba. I'm trying to call a macro if a specific cell in a range is selected.
This is what I've coded.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Start_Range As Range
Set Start_Range = Range("C2:C1001")
Dim End_Range As Range
Set End_Range = Range("D2:D1001")
If Target.Range = Start_Range or Target.Range = End_Range Then
frmCalendar.Show
End If

End Sub

However, I'm getting a Compile error stating Argument not optional.

Can anyone please guide me to code this correctly?

Thanks in advance.

Sam

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Trying to call a macro on selection of a cell in a range

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Start_Range As Range
Set Start_Range = Range("C2:C1001")
Dim End_Range As Range
Set End_Range = Range("D2:D1001")
If Not Intersect(Target, Start_Range) Is Nothing Or _
Not Intersect(Target, End_Range) Is Nothing Then

frmCalendar.Show
End If
End Sub


--
__________________________________
HTH

Bob

"The Narcissist" wrote in message
...
Hi,

This might come across as a novice question, as I am in fact, a novice at
vba. I'm trying to call a macro if a specific cell in a range is selected.
This is what I've coded.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Start_Range As Range
Set Start_Range = Range("C2:C1001")
Dim End_Range As Range
Set End_Range = Range("D2:D1001")
If Target.Range = Start_Range or Target.Range = End_Range Then
frmCalendar.Show
End If

End Sub

However, I'm getting a Compile error stating Argument not optional.

Can anyone please guide me to code this correctly?

Thanks in advance.

Sam



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
How can run a macro ( call a macro) on selection of any filtercriteria? [email protected] Excel Worksheet Functions 7 February 20th 09 12:34 AM
call range by cell value Roland Excel Worksheet Functions 1 January 15th 09 04:32 PM
Call Macro when Cell within Range Changes Andibevan[_2_] Excel Programming 4 March 24th 05 04:28 PM
Passing a range in a macro call Otto Moehrbach[_6_] Excel Programming 6 November 15th 04 02:31 PM
Macro to change list box input range based on selection made in another cell Sue[_6_] Excel Programming 3 October 7th 04 06:45 PM


All times are GMT +1. The time now is 07:14 PM.

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

About Us

"It's about Microsoft Excel"