+ Reply to Thread
Results 1 to 3 of 3

setfocus to command button from Cell

  1. #1
    Registered User
    Join Date
    07-15-2012
    Location
    Saudi Arabia
    MS-Off Ver
    Excel 2010
    Posts
    5

    Question setfocus to command button from Cell

    Greeting everyone,

    I made a simple program to calculate the electric bill. The user has to enter a value in a cell (D6) then he or she should hit enter from the keyboard. Then, he should click on a button, on the same sheet, or hit enter again to get the results in two different cells (D8 an D10).
    I'm not using forms or text box.
    I looked everywhere for an expression (code) to set the focus to the command button after entering the value in the cell (D6) and hit enter on a keyboard, but I didn't find any thing useful.
    I don't have much experience in excel programming, however, I like to learn some of it.
    Please give me your valuable advice to win the war.

    Regards,

    Wael

  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: setfocus to command button from Cell

    Hello Waelkash,

    Welcome to the Forum!

    The code below assumes the name of the Command Button on the worksheet is "CommandButton1". This code is pasted into the worksheet module that has the command button. Your code that you want to execute when the user clicks or hits return would replace the "Beep" command in the code.
    Please Login or Register  to view this content.
    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
    Registered User
    Join Date
    07-15-2012
    Location
    Saudi Arabia
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: setfocus to command button from Cell



    Thank you Leith

    Your codes is working fine

    I have two more wondarings.

    1. Would you please explain how these codes works
    2. I hope it is possible to make the CommandButton1 do the event when pressing enter on the keyboard also. Now it only beeps.

    I appreciate your concern.

    Have a nice life.

    Wael
    Last edited by Cutter; 07-15-2012 at 08:53 AM. Reason: Removed whole post quote

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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