View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Mik Mik is offline
external usenet poster
 
Posts: 42
Default Start Macro when specific Cells are selected

On 17 Nov, 18:37, Gord Dibben <gorddibbATshawDOTca wrote:
Substitute msgbox for your code or macro.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Me.Range("C3,C4,C5")) Is Nothing Then Exit Sub
MsgBox Target.Address
End Sub

Gord Dibben *MS Excel MVP

On Tue, 17 Nov 2009 02:47:12 -0800 (PST), Mik
wrote:



On 17 Nov, 09:43, Mik wrote:
I have a range of cells b3:b5 which show UserNames of people who will
use the spreadsheet.
The adjacent cells c3:c5 allow a manual input from the user.
The user must enter the info in their specific adjacent cell only.


So, when any of these cells c3:c5 are selected, i wish to run a macro
(preferably before user input) which will check to see that the
current user is entering info within the correct cell.
I determine the user with the Environ("username") function.


For info, i am using Excel 2007.


My code at present is:-


Private Sub Worksheet_Change(ByVal Target As Range)
* * If Target.Address = "$c$3" Then
* * * * If Range("b3").Value = Environ("username") Then 'allow entry
* * * * * * Exit Sub
* * * * Else
* * * * * * MsgBox ("Wrong User Input!")
* * * * End If
* * Else
'code to repeat for $c$4, and $c$5 etc...
* * End If
End Sub


Sorry,


When I look back at my previous entry it does not read very clear.


Basically, can anybody advise me how to Run a Macro when a specific
cell is selected, using Excel 2007?
Macro must run before text is entered into the cell.


Thanks in advance.


Mik- Hide quoted text -


- Show quoted text -





Thank you both very much for your assistance.
That did exactly what i wanted.

Mik