+ Reply to Thread
Results 1 to 18 of 18

Code to Enter Clipboard Data Upon Left-Click?

  1. #1
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    33

    Code to Enter Clipboard Data Upon Left-Click?

    Morning all,

    Would anyone know if there's a way to auto-paste copied data from the clipboard into a cell upon a single left-click? If so, I'd need this to apply to ONLY cell range A3:A50.

    Thanx a lot,
    Frithlethrend

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Code to Enter Clipboard Data Upon Left-Click?

    Hello frith,

    Welcome to the Forum!

    Is this for only a single worksheet or all worksheets in the workbook?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Code to Enter Clipboard Data Upon Left-Click?

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    33

    Re: Code to Enter Clipboard Data Upon Left-Click?

    Quote Originally Posted by Whizbang View Post
    Please Login or Register  to view this content.


    Hey, thanx, that works great - only thing is I need it to work with the existing Worksheet_SelectionChange, below:

    Please Login or Register  to view this content.


    Sorry, I forgot this was in there. Any way to "blend" them such that they don't conflict?

    Thanx again,
    Frith

  5. #5
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Code to Enter Clipboard Data Upon Left-Click?

    Please Login or Register  to view this content.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Code to Enter Clipboard Data Upon Left-Click?

    Frith, please take a few minutes to read the forum rules about crossposting.

    Thank.
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    33

    Re: Code to Enter Clipboard Data Upon Left-Click?

    Hi again,

    I sure will... Also, a problem arose with that code - whenever the clipboard is empty and I click a cell in that range, I get a runtime error ("paste failed"). Any way to avoid this annoyance, other than having some kind of "default data" always pre-loaded on it? Also, I have cells in column A merged with those in B, which somehow disallows this code from executing...?

    Thanx,
    Frith
    Last edited by frith; 05-26-2011 at 01:44 PM.

  8. #8
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Code to Enter Clipboard Data Upon Left-Click?

    The problem with this approach is that the clipboard could have just about anything in it, which could lead to all sorts of issues. The code below will at least notify the user if the clipboard is empty and will not stop the code.

    Please Login or Register  to view this content.
    As for the issue of the merged cell, this bit here:
    Please Login or Register  to view this content.
    Says to only run the encapsulated code only if one cell is selected. If more than one is selected, then the code will not do anything. I added this because I didn't know how you would want to handle things like the user selecting the entire column, or the entire sheet. It would mean pasting to ALL cells selected.

  9. #9
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    33

    Re: Code to Enter Clipboard Data Upon Left-Click?

    Thank you, indeed... Just one thing with the merged cell issue, Ummm... It's still doing nothing when I click it (say, A5, which is really "A5 merged with B5")... That 2nd, seperate code block you posted... am I supposed to do something with that?

    TY,
    Frithlethrend

  10. #10
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Code to Enter Clipboard Data Upon Left-Click?

    What I am saying is because those cells are merged, when you select that merged cell, you are actually selecting 2 or more cells. The code I supplied specifically only runs when one cell is selected. This is to prevent issues that will occure if the user selects the entire column, row, sheet, or just a large range. If that test for Target.count were not in there, the code would paste to each and every cell selected, and therefore turn your sheet into garbage.

    There are a few potential solutions for you:
    1: Remove the If Target.Count = 1 statement. This, like I say above, could lead to major issues if your users do not think before they act.

    2: Change the If Target.Count = 1 statement to something like If Target.Count < 5. This will still mean the clipboard will be pasted into each cell selected, but at least it is only five cells, and hopefully the user will know what they are doing.

    3: You could add a loop that runs through each cell in the Target range and pastes into only cells within the range of A3:A50

    4: Have the code only paste to the Active cell.

    5: Prompt the user before pasting to ensure they want to paste into the selected cells.

    These are just a few options, but without knowing specifically what you are trying to accomplish, I can't make any one recommendation.

    Is there a reason those cells are merged? Cell merging can wreak havoc on code, especially when you are pasting. I recommend avoinding merging cells unless completely unavoidable.

  11. #11
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    33

    Re: Code to Enter Clipboard Data Upon Left-Click?

    Hi,

    Option 2 worked fine for merged cells. Actually, if I select more than 1 merged cell, nothing even gets pasted; it only works if I select just 1 cell, which is what I needed.


    Thanx again!!

  12. #12
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    33

    Re: Code to Enter Clipboard Data Upon Left-Click?

    Hi Whizbang,

    Sorry to belabor the thread, but I ran into another issue with that pasting code: it works perfectly when copying/pasting within "EXCEL", but it doesn't work when copying data from an outside App. (It's a proprietary App. you've probably never heard of, but is windows-based). When I try to paste, that "empty clipboard" message appears, even though I can still paste the data via double-clicking a cell... Any ideas on how to make this work (elsewise I'm screwed)?

    Thanx yet again,
    Frith

  13. #13
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Code to Enter Clipboard Data Upon Left-Click?

    Try this.

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    33

    Re: Code to Enter Clipboard Data Upon Left-Click?

    Sweet... But I just noticed that when it pastes, it overides the cell format (i.e., it pastes the wrong font, alignment, etc.) Any way to only paste the "value"? Also (sorry), is it possible to have this code only paste ONE time (i.e., execute only on the initial paste, per cell)?

    Thanx,
    Frith
    Last edited by frith; 05-27-2011 at 01:13 PM.

  15. #15
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Code to Enter Clipboard Data Upon Left-Click?

    Try this:
    Please Login or Register  to view this content.


    I am not sure what you mean by the second question. Do you mind clarifying and providing examples?

  16. #16
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    33

    Re: Code to Enter Clipboard Data Upon Left-Click?

    Hey again...

    Yeah, the format issue is good, but it still allows for subsequent auto-pasting... I'm just trying to get it so that if I auto-paste "hello" now, it won't auto-paste "goodbye" five seconds later in the same cell subsequently (i.e., I want "hello" to get pasted in A5 the 1st time, but not "goodbye" the 2nd time in A5, etc., etc.). However, I would need to allow for "manual" cell edits.

    Thanx and sorry for the trouble,
    Frith

  17. #17
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Code to Enter Clipboard Data Upon Left-Click?

    Ah. I see what you mean, now.

    The code below tests the active cell (the cell you click) to see if it is blank. If it is blank, it will paste. If not, it will not paste and just let you edit normally.

    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    33

    Re: Code to Enter Clipboard Data Upon Left-Click?

    Awesome - great job! What comes around, goes around...

    Frith

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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