+ Reply to Thread
Results 1 to 13 of 13

Run macro when the enter key (only) is pressed

  1. #1
    Registered User
    Join Date
    12-17-2014
    Location
    Perth, Australia
    MS-Off Ver
    Windows 7
    Posts
    85

    Run macro when the enter key (only) is pressed

    I would like a macro to run every time I press the enter key anywhere on a specific sheet. I will be entering data in several cell before pressing enter, so the macro only needs to run once enter is press and not when the cells are changed.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Run macro when the enter key (only) is pressed

    This goes in the worksheet module, right click the sheet tab and select View Code
    One is the worksheet change, and the other is the selection change

    Use the one you want.
    Ussually one would onlt want the code to run when a specific range is selected, but you have not determined that.
    Please Login or Register  to view this content.
    Look at my other examples here.
    http://www.davesexcel.com/vbacodes.htm#858300135

  3. #3
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Run macro when the enter key (only) is pressed

    Try:
    Please Login or Register  to view this content.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  4. #4
    Registered User
    Join Date
    12-17-2014
    Location
    Perth, Australia
    MS-Off Ver
    Windows 7
    Posts
    85

    Re: Run macro when the enter key (only) is pressed

    Deleted reply

  5. #5
    Registered User
    Join Date
    12-17-2014
    Location
    Perth, Australia
    MS-Off Ver
    Windows 7
    Posts
    85

    Re: Run macro when the enter key (only) is pressed

    Hi Olly,

    I've manage to get yours to work, but how do I call the macro from this point. I removed the "MsgBox "Enter pressed to commit changes"" and replaced it with Call Macro (the macro is called macro) and an error run time appears.

    Thanks,

  6. #6
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Run macro when the enter key (only) is pressed

    If I emphasize the (ONLY) word.. and ignore your #ofPost.. and assume you as a intermediate level of Excel user.. then

    I would like to suggest.. this one..

    On this_Workbook..

    Please Login or Register  to view this content.
    In a separate Module..
    Please Login or Register  to view this content.

    BTW.. dont forget to change all the {CAPSLOCK} to {ENTER}


    EDIT: Please Ignore.. as I think.. you really need (only) Worksheet_change events..
    Last edited by Debraj Roy; 12-17-2014 at 12:49 PM.
    Regards!
    =DEC2HEX(3563)

    If you like someone's answer, click the star to give them a reputation point for that answer...

  7. #7
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Run macro when the enter key (only) is pressed

    Quote Originally Posted by Jeckford View Post
    Hi Olly,

    I've manage to get yours to work, but how do I call the macro from this point. I removed the "MsgBox "Enter pressed to commit changes"" and replaced it with Call Macro (the macro is called macro) and an error run time appears.

    Thanks,
    Should work. This does:

    Please Login or Register  to view this content.
    If that's still not working, try attaching your workbook so I can see what's going on.

  8. #8
    Registered User
    Join Date
    12-17-2014
    Location
    Perth, Australia
    MS-Off Ver
    Windows 7
    Posts
    85

    Re: Run macro when the enter key (only) is pressed

    Hi Dave,

    I've put the code in and it runs every time I select a cell, I only need it to run when I press the "Enter" key. Am I missing something?

    Thanks,

  9. #9
    Registered User
    Join Date
    12-17-2014
    Location
    Perth, Australia
    MS-Off Ver
    Windows 7
    Posts
    85

    Re: Run macro when the enter key (only) is pressed

    Hi Olly,

    Okay it wasn't working a minute ago, but now it seems to be all good.

    Thanks heaps for your help. If it comes up with an error again I'll send you a sample.

    Thanks again.

  10. #10
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Run macro when the enter key (only) is pressed

    My idea was that everytime you press enter you would be selecting another cell anyway. So why not use the selection_change event.

    Is there a specific range you would want the code to activate?

  11. #11
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Run macro when the enter key (only) is pressed

    Check post # 6..

  12. #12
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Run macro when the enter key (only) is pressed

    Another approach.. to limit it within a sheet..


    Please Login or Register  to view this content.

  13. #13
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Run macro when the enter key (only) is pressed

    and final one.. with API..

    On a Module ..

    Please Login or Register  to view this content.
    and in sheet_SelectionChange event..
    Please Login or Register  to view this content.

+ 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. Run a macro when Enter or Tab key is pressed
    By anandvh in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-18-2017, 10:54 PM
  2. Run macro when enter key pressed in certain range
    By mr_mango81 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-05-2014, 01:46 AM
  3. Run a macro when Enter is pressed
    By Speclt in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-19-2011, 01:17 AM
  4. Run a macro everytime enter is pressed
    By mr_teacher in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-04-2008, 01:22 PM
  5. Run a macro when 'Enter' is pressed?
    By jcup in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-28-2007, 02:11 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