Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Linking code to a cell


Hi Guys,

I know there is a way of automatically runnig a piece of code when
user selects a certain cell (eg if they select cell A1 code A runs
whereas if they selecet cell B1 code B may run).

However what i woudl like to do, and what i am struggling to do is.
Run the code if the cell selected is within a certain range. Fo
example, if the range is a1:d5 and user selects cell b3 it runs som
code, where as if the user selects E2 it will not as this is not in th
code.

Is there a simple way of doing this? Its driving me crazy.

Regards,

Fernand

--
Fernandoalbert
-----------------------------------------------------------------------
Fernandoalberte's Profile: http://www.excelforum.com/member.php...fo&userid=2449
View this thread: http://www.excelforum.com/showthread.php?threadid=38344

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Linking code to a cell

How about naming the range a1:d5 as "HotRange", and then testing whether the clicked cell is within
HotRange before continuing with the code execution.
Rgds,
Scott

"Fernandoalberte" <Fernandoalberte.1rfgqb_1120115111.6807@excelfor um-nospam.com wrote in message
news:Fernandoalberte.1rfgqb_1120115111.6807@excelf orum-nospam.com...
|
| Hi Guys,
|
| I know there is a way of automatically runnig a piece of code when a
| user selects a certain cell (eg if they select cell A1 code A runs,
| whereas if they selecet cell B1 code B may run).
|
| However what i woudl like to do, and what i am struggling to do is.
| Run the code if the cell selected is within a certain range. For
| example, if the range is a1:d5 and user selects cell b3 it runs some
| code, where as if the user selects E2 it will not as this is not in the
| code.
|
| Is there a simple way of doing this? Its driving me crazy.
|
| Regards,
|
| Fernando
|
|
| --
| Fernandoalberte
| ------------------------------------------------------------------------
| Fernandoalberte's Profile: http://www.excelforum.com/member.php...o&userid=24493
| View this thread: http://www.excelforum.com/showthread...hreadid=383440
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Linking code to a cell

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng1, rng2 As Range
Set rng1 = Me.Range("a1") 'first tested area
Set rng2 = Me.Range("b1") 'second tested area
If Not Application.Intersect(rng1, Target) Is Nothing Then MsgBox "A1
selected"
If Not Application.Intersect(rng2, Target) Is Nothing Then MsgBox "B1
selected"
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Linking code to a cell

In your Worksheet code module:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Range("A1:D5"), Target) Is Nothing Then
Call MyMacro
End Sub

Mike F

"Fernandoalberte"
<Fernandoalberte.1rfgqb_1120115111.6807@excelfor um-nospam.com wrote in
message news:Fernandoalberte.1rfgqb_1120115111.6807@excelf orum-nospam.com...

Hi Guys,

I know there is a way of automatically runnig a piece of code when a
user selects a certain cell (eg if they select cell A1 code A runs,
whereas if they selecet cell B1 code B may run).

However what i woudl like to do, and what i am struggling to do is.
Run the code if the cell selected is within a certain range. For
example, if the range is a1:d5 and user selects cell b3 it runs some
code, where as if the user selects E2 it will not as this is not in the
code.

Is there a simple way of doing this? Its driving me crazy.

Regards,

Fernando


--
Fernandoalberte
------------------------------------------------------------------------
Fernandoalberte's Profile:
http://www.excelforum.com/member.php...o&userid=24493
View this thread: http://www.excelforum.com/showthread...hreadid=383440



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
split post code (zip code) out of cell that includes full address Concord Excel Discussion (Misc queries) 4 October 15th 09 06:59 PM
linking excel and word files with vb code Muneyi Mhishi Excel Programming 0 December 16th 04 04:27 PM
linking code across different workbooks pmlevy Excel Programming 0 October 11th 04 06:45 AM
linking excel sheet to access using code Charles Excel Programming 0 January 30th 04 07:24 AM
Linking VBA code to spreadsheet mark_varney47 Excel Programming 5 September 8th 03 12:27 PM


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