Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-11-15
3
Medium Priority
?
400 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 1000 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 10

Assisted Solution

by:Tom
Tom earned 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

719 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