Solved

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

739 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