LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Click cell to activate macro

Bob,

I tried this by putting a message box in each case and found that I had to
double click the cell AND then move to another cell before the message
box poped up
Is there a way to do this without having to move to another cell?



Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1:H10"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Row
Case 2: MsgBox "row 2"
Case 3: MsgBox "row 3"
Case 4: MsgBox "row 4"
Case 5: MsgBox "row 5"
Case 6: MsgBox "row 6"
Case 7: MsgBox "row 7"
Case 8: MsgBox "row 8"
Case 9: MsgBox "row 9"

End Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub
Billy Rogers

Dallas,TX


"Bob Phillips" wrote:

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1:H10"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Row
Case 5: 'do something
Case 9: 'do something else
'etc.
End Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.





--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Bob" wrote in message
...
I want to run a macro when the user clicks in a specific cell. In a
personal worksheet I put a button on the page and tied a macro to the
button. In that case there was only one button. In the present case, the
macro needs to do different things depending on what row is clicked.
Because someone else will be maintaining the workbook and because the data
will change frequently (with rows being added and deleted), I don't want

to
put a button in each row.

My macro will determine its row, pull data from the same row in another
worksheet, and display the data in a text box. I tried using a hyperlink
from the source page to the data page, but the user didn't like that.

I'm pretty sure I can get the macro to figure out the row of the cell that
was clicked, so I really need to write only one macro. Is there a way I

can
fire a macro when a user clicks in a cell?

BTW, I thought about having the user select a cell and then use the menus

to
launch the macro, but the user wants something simpler.

Thanks,
Bob





 
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
Cell requires double click to 'activate' date format change BLTibbs Excel Discussion (Misc queries) 4 April 2nd 23 01:38 PM
how to activate macro from cell artzuka Excel Discussion (Misc queries) 2 January 6th 09 09:12 PM
The cell I click on when coming from another app doesn't activate Dave Excel Discussion (Misc queries) 1 October 4th 07 11:01 AM
How do I activate the right mouse click in Excel? Kcm Excel Discussion (Misc queries) 0 March 28th 06 08:14 AM
activate a cell value through a macro TUNGANA KURMA RAJU Excel Discussion (Misc queries) 1 November 10th 05 08:48 AM


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