Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help needed starting a macro

I want too start a macro when a cell in a certain range is left clicke
or selected by navigating to it using the arrow keys.....i.e if cell i
selected in range xx:yy then run macro or when cell in range i
highlighted by arrow keys.im new to VBA so an idiots guide on how to d
this would be very well apreciated!

Thanks in advance!
Simo

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Help needed starting a macro

Right click on the sheet tab and select view code.

In the resulting module, at the top, in the left dropdown, select Worksheet
and in the right dropdown, select SelectionChange

This puts in a declaration for the selectionchange event

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub

Target is a range reference to the cell selected by the user using the
methods you describe (or any other way they get there).

You can then test if Target is in your range

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
if target.count 1 then exit sub
if not intersect(target, Range("A1:B50")) is nothing then
' selected cell is in the range A1:B50

End if
End Sub

If your code will select another cell inside that range, then you would need
to turn events off (and back on again when done) so you don't get recursive
calls to the event.

--
Regards,
Tom Ogilvy

End Sub
"Simon Lloyd " wrote in message
...
I want too start a macro when a cell in a certain range is left clicked
or selected by navigating to it using the arrow keys.....i.e if cell is
selected in range xx:yy then run macro or when cell in range is
highlighted by arrow keys.im new to VBA so an idiots guide on how to do
this would be very well apreciated!

Thanks in advance!
Simon


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default Help needed starting a macro

Use the Worksheet 's SelectionChange Event In your Project window
And do something like thi

Private Sub Worksheet_SelectionChange(ByVal Target As Range
Set MyRange = Range("A1:D20"
Set isect = Application.Intersect(MyRange,(Target.Address)
If isect Is Nothing Then Exit Su
' Put what your code is here
End Su

anytime a cell is selected this code will fire but fill only Run your code if its within your range
----- Simon Lloyd wrote: ----

I want too start a macro when a cell in a certain range is left clicke
or selected by navigating to it using the arrow keys.....i.e if cell i
selected in range xx:yy then run macro or when cell in range i
highlighted by arrow keys.im new to VBA so an idiots guide on how to d
this would be very well apreciated

Thanks in advance
Simo


--
Message posted from http://www.ExcelForum.com


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Help needed starting a macro

Believe this will cause an error:

Set isect = Application.Intersect(MyRange,(Target.Address))

you can't intersect a range and a string.

--
Regards,
Tom Ogilvy


"chris" wrote in message
...
Use the Worksheet 's SelectionChange Event In your Project window
And do something like this

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set MyRange = Range("A1:D20")
Set isect = Application.Intersect(MyRange,(Target.Address))
If isect Is Nothing Then Exit Sub
' Put what your code is here
End Sub

anytime a cell is selected this code will fire but fill only Run your code

if its within your range.
----- Simon Lloyd wrote: -----

I want too start a macro when a cell in a certain range is left

clicked
or selected by navigating to it using the arrow keys.....i.e if cell

is
selected in range xx:yy then run macro or when cell in range is
highlighted by arrow keys.im new to VBA so an idiots guide on how to

do
this would be very well apreciated!

Thanks in advance!
Simon


---
Message posted from http://www.ExcelForum.com/




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help needed starting a macro

Hi guys at the bottom of the page someone has posted a solution to wha
i need, as Tom said the isect did cause an error as did the wor
"Address" so i took this out and DIM isect as Variant, and also had t
DIM myrange as range....it then worked perfect!

Thank

--
Message posted from http://www.ExcelForum.com

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
starting macro again Davidm Excel Discussion (Misc queries) 3 June 3rd 09 04:12 AM
Starting macro Davidm Excel Discussion (Misc queries) 3 June 3rd 09 04:09 AM
Starting A Macro zephyr Excel Discussion (Misc queries) 2 November 10th 06 12:03 PM
starting a macro at startup chip_pyp Excel Discussion (Misc queries) 1 March 22nd 06 06:59 PM
Macro not starting Larry[_12_] Excel Programming 1 January 15th 04 04:52 PM


All times are GMT +1. The time now is 12:25 AM.

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"