Solved

Can I run a macro when I click on a cell?

Posted on 2010-11-15
3
399 Views
Last Modified: 2013-11-25
I have a column that holds a key number that I would like to place into another cell when I click on the cell.  Right now, I copy the row and paste it up at the top.  I would like to know how I can make this something that happens upon clicking the cell...instead of copying and pasting.  I have a right-click option for now, but as you will see in the XLS, it will paste the key field at the top of the screen and bring in the "often wordy" description.

My thoughts is that this code would only run if you clicked a cell in column G since that is the key #.  Thoughts?
0
Comment
Question by:sopczak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 33

Accepted Solution

by:
jppinto earned 250 total points
ID: 34138267
Try this way:

jppinto
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If (Not Intersect(Target, Range("G:G")) Is Nothing) Then 
       'your code here
    End If
End Sub

Open in new window

0
 
LVL 9

Assisted Solution

by:Tom
Tom earned 250 total points
ID: 34138271
yes by double cliking in it:
Open the VBE (Alt+F11) and then double click the Sheet in the Project Explorer the code applies to. This is where the code must be placed

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Call Mycode
End Sub
0
 

Author Closing Comment

by:sopczak
ID: 34138345
Both solutions worked great.  I only marked the one as "Best Solution" b/c it is what I specifically asked for.  However, the double-click works great too.  Thanks for the help!!!
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question