Macro and Text

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to have the text in a cell launch a macro when clicked, or
must I use an object?
 
LDanix said:
Is it possible to have the text in a cell launch a macro when clicked, or
must I use an object?

I think so. Isn't there an event that gets called when something has been
entered into a cell?

/Fredrik
 
Hi, you could use procedures like this. It will pass the cell address,
which you could then test and run macros accordingly.

Worksheet_SelectionChange(ByVal Target As Excel.Range, Cancel As
Boolean)
Worksheet_BeforeDoubleClick(ByVal Target As Excel.Range, Cancel As
Boolean)

HTH--Lonnie M.
 
Lonnie M. said:
Hi, you could use procedures like this. It will pass the cell address,
which you could then test and run macros accordingly.

It passes the cell object, not its address. You can extract the value from
the object, its row, it's parent, its column, or even its address.
 
An example

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
If Target.Address = "$F$5" Then
Call myMacro
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

RP
(remove nothere from the email address if mailing direct)
 
Which parts of the code do I need to enter the data from my sheet rather than
what is currently there?
 
It was provided as an example as Tom said, but it was meant as a fairly
close example, as you said you wanted to launch a macro by clicking a cell.
All you need to do is insert it in the worksheet, as described, and change
the statement
Call myMacro
to a call to the macro that you have written, and change $F$5 to the cell
you want as you click cell (with the $ signs - very important).

--

HTH

RP
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top