Solved

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

Posted on 2010-11-15
3
393 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
3 Comments
 
LVL 33

Accepted Solution

by:
jppinto earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now