Solved

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

Posted on 2010-11-15
3
395 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

740 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