+ Reply to Thread
Results 1 to 7 of 7

Getting code to find the selected Active cell

  1. #1
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Central Ohio
    MS-Off Ver
    Excel 2000, and 2010
    Posts
    654

    Getting code to find the selected Active cell

    Being a novice in VBA I have run into a problem with some code.

    What I want to do is to beable to select a cell in the range K8:K26 and have the value in that cell copied to cell Z2.

    Here is what I have been able to put together so far but I cant seem to get the code to find the first active cell I have selected.

    Please Login or Register  to view this content.
    JIm O

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Getting code to find the selected Active cell

    Remove the Select from ActiveCell line:
    Please Login or Register  to view this content.
    If someone has helped you then please add to their Reputation

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    27,194

    Re: Getting code to find the selected Active cell

    Your code does not check that the selection is in the specified range. If it matters, it should be checked.
    You do not need the Select.
    Why are you using Offset? That does not copy the active cell, it copies the cell 7 columns to the right of the active cell.

    The following code does what your description says:
    Quote Originally Posted by JO505 View Post
    What I want to do is to beable to select a cell in the range K8:K26 and have the value in that cell copied to cell Z2.
    But what do you mean the "first active cell I have selected"?
    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Central Ohio
    MS-Off Ver
    Excel 2000, and 2010
    Posts
    654

    Re: Getting code to find the selected Active cell

    pj's suggestion worked fine.

    How do I limit the selection to only range K8:K26?

    JIm O

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    27,194

    Re: Getting code to find the selected Active cell

    If pjwhitfield's suggestion worked for you then there's something about what you want your code to do that you didn't describe. That code (and your code) takes a value selected in column K and copies the value from column R in the same row into Z2. Is that what you need, rather than "select a cell in the range K8:K26 and have the value in that cell copied"?

    My If statement checks to see if the active cell is in K8:K26, and does the copy only if it is in that range. Your code (and pjwhitfield's update) will do the copy no matter where the user clicks.

  6. #6
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Central Ohio
    MS-Off Ver
    Excel 2000, and 2010
    Posts
    654

    Re: Getting code to find the selected Active cell

    I probably didnt describe what I am looking for as well as I should have.

    I have a data set, populated through a dropdown list, that shows sales made to the selected customer. Column K (K8:K26) is a list of invoice numbers for each transaction and column "R" (7 columns to the right of the invoice number) is the row number for each transaction. My final goal is to be able to select an invoice number, click a button 'shape' and open the sales log to that transaction. I would also like to limit the code to only run if a cell in the column K range is selected to prevent the wrong data to be copied into cell Z2.

    Here is the code I have to open the sales log.

    Please Login or Register  to view this content.
    As I said I am very new to VBA and I am sure there are better ways to go about this but this is where I am now and am trying to learn.

    Jim O
    Last edited by JO505; 01-18-2015 at 06:19 PM. Reason: Typo

  7. #7
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Central Ohio
    MS-Off Ver
    Excel 2000, and 2010
    Posts
    654

    Re: Getting code to find the selected Active cell

    To the MODs,

    There are 2 posts about this topic that I mistakenly started. The other post can be deleted.

    To others,

    I would still like to combine the 2 codes I have posted i this thread.
    I apologize for the disconnction in this post. My only excuse is that not knowing VBA well enough, and starting out on the wrong foot.

    As I said in the last post I have a data set populated from a drop down list (J8:R26) and I would like to select any cell in column K and only column K ( K contains the invoice number) before the code will run. When selected the sheet 'Sales Log' will open to the selected row.

    Hopefully this is not too confusing.

    Jim O

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to retrieve the value of the active selected cell
    By MachtiSonni in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-06-2013, 03:36 PM
  2. Format active cell and adjacent when selected??
    By strud in forum Excel General
    Replies: 1
    Last Post: 07-09-2013, 10:25 AM
  3. Function which references active or selected cell
    By ComcoDG in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-23-2008, 12:27 PM
  4. Check selected cells are right of active cell
    By papata123 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-12-2007, 02:10 PM
  5. selecting row from active cell selected
    By mikla in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-07-2006, 01:15 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1