+ Reply to Thread
Results 1 to 19 of 19

Can you execute a macro or shortcut keystroke within an "IF" function?

  1. #1
    Registered User
    Join Date
    12-12-2013
    Location
    Hollister, CA
    MS-Off Ver
    Excel 2003
    Posts
    16

    Can you execute a macro or shortcut keystroke within an "IF" function?

    Situation: I have 4 rows that are Hidden. I have a checkbox that is linked to cell "D6". The question before the checkbox is "Do you have financing?". If the user leaves the checkbox unchecked, cell "D6" stays FALSE and the 4 rows remain Hidden. If the user checks the checkbox, cell "D6" changes to TRUE and the 4 rows become Unhidden. The 4 rows display cells that the user can fill in the requested information. I created Macro1 that Unhides the 4 rows and Macro2 that Hides the 4 rows. Ideally, the "IF" statement would look like =IF(D6,Macro1,Macro2), but it does not work. Is there anyway I can accomplish what I want to do?? Maybe not using the IF function, but some other function?? I really appreciate your help in this matter. Ty
    Last edited by Tholmq; 12-15-2013 at 11:12 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Can you execute a macro or shortcut keystroke within an "IF" function?

    You can assign a macro to the checkbox so the macro runs every time the checkbox gets clicked. Then the macro can call Macro1 in one case and Macro2 in the other. But the approach is different depending on whether you used a Forms checkbox or an ActiveX checkbox. What type did you use? If you don't know, can you attach your file?
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Can you execute a macro or shortcut keystroke within an "IF" function?

    You can do something like:
    Please Login or Register  to view this content.
    Then assign this macro to a shortcut key, and/or the click/change event of the checkbox.

  4. #4
    Registered User
    Join Date
    12-12-2013
    Location
    Hollister, CA
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Can you execute a macro or shortcut keystroke within an "IF" function?

    6String & Millz both approaches are very interesting. 6string I am pretty sure it is an ActiveX checkbox. I tried to attach a file to this reply, but couldn't figure out how to do it. 6String, you said "Then the macro can call Macro1 in one case and Macro2 in the other." How do you do this? Is it through the Properties box of the checkbox? Millz, you said "Then assign this macro to the click/change event of the checkbox." I did create this macro as macro3 but I couldn't assign it to the click/change event of the checkbox. Is this also done through the Properties box? I really appreciate you two responding so quickly. You don't know how many days I have spent trying to solve this problem. Again, thank you, Ty

  5. #5
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Can you execute a macro or shortcut keystroke within an "IF" function?

    If you're putting into a click/change event of the checkbox, it would be better to just look at the checkbox's value. This code should go into the worksheet's code.

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    12-12-2013
    Location
    Hollister, CA
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Can you execute a macro or shortcut keystroke within an "IF" function?

    Millz, based on your post, I put the following in the worksheet's code:

    Please Login or Register  to view this content.
    I can't believe it; it worked PERFECT!!!! I have to do a similar thing with a drop down box, where depending on what item is selected, different rows will be hidden or unhidden. I will play with it to see if I can get it to work. Again, thank you so very much. Ty ps, how do you attach an excel file?
    Last edited by 6StringJazzer; 12-13-2013 at 08:19 AM. Reason: code tags

  7. #7
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Can you execute a macro or shortcut keystroke within an "IF" function?

    To attach a file, click Go Advanced. Look for the paperclip icon in the rich text box editor, and click Add files.

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Can you execute a macro or shortcut keystroke within an "IF" function?

    Tholmq, if that code worked for you that means you have an ActiveX checkbox.

    Please take the time to review our rules. There aren't many, and they are all important. We require code tags; I have added them for you this time because you are new.

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

  9. #9
    Registered User
    Join Date
    12-12-2013
    Location
    Hollister, CA
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Can you execute a macro or shortcut keystroke within an "IF" function?

    6String, I apologize for not following Rule 3. Now I know better.

    6String and Millz: I am having problems doing the combo box, I mentioned previously. Maybe, I should be using something other than a combo box?

    Situation: Rows 13, 14, 15 & 16 are Hidden. The wording prior to the combo box is "Who are you financing with?" The combo box contains the following: None, ABC, XYZ, Other. If the user selects None, all rows stay hidden. If the user selects ABC, Row 13 becomes Unhidden. If the user selects XYZ, Row 14 becomes Unhidden. If the user selects Other, Rows 15 & 16 become Unhidden. By the same token, if the user accidentally selects ABC and Row 13 becomes Unhidden, then selects XYZ, Row 13 needs to be Hidden and Row 14 need to becomes Unhidden.

    I don't know if this is possible with a combo box? Your assistance is really appreciated. Thank you in advance. Ty

  10. #10
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Can you execute a macro or shortcut keystroke within an "IF" function?

    If you are using a combo box instead, then you need to use the Change event.

    As for the hiding/unhiding of rows, just make it that all rows are unhidden first, then hide the necessary rows based on selection.

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    12-12-2013
    Location
    Hollister, CA
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Can you execute a macro or shortcut keystroke within an "IF" function?

    Hello Millz, I have tried several things based on what you had provided in your last post. I will try to attach this excel file to this post. The file is a work in progress and may look confusing. Just concentrate on ComboBox2.... Or if you have any suggestions about the overall scope of the document, please don't hesitate to comment. Thank you in advance for your assistance. Ty
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    12-12-2013
    Location
    Hollister, CA
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Can you execute a macro or shortcut keystroke within an "IF" function?

    The attachment didn't work before. Maybe it will work now????
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    12-12-2013
    Location
    Hollister, CA
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Can you execute a macro or shortcut keystroke within an "IF" function?

    Millz, what am I doing wrong in attaching the file????????

  14. #14
    Registered User
    Join Date
    12-12-2013
    Location
    Hollister, CA
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Can you execute a macro or shortcut keystroke within an "IF" function?

    Cas_Test3.xls I don't know if this worked

  15. #15
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Can you execute a macro or shortcut keystroke within an "IF" function?

    Tholmq, you successfully posted the same file three times in the span of a half hour. You may want to take a breath before repeating posts if you think something didn't work. Also, please note that when composing your post, there is a button beneath the edit box labeled Go Advanced. If you press that, you will then see a preview of what your post will look like, plus can continue editing in the box below. Then if you need to refresh the preview, you can press the Preview Post button now available under the edit box.

  16. #16
    Registered User
    Join Date
    12-12-2013
    Location
    Hollister, CA
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Can you execute a macro or shortcut keystroke within an "IF" function?

    Hello 6String. Again, I apologize for making all of these newbie mistakes. I will do better. BTW, do you have any suggestions regarding my latest problem with combo boxes?? Ty

  17. #17
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Can you execute a macro or shortcut keystroke within an "IF" function?

    Try changing to this:

    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    12-12-2013
    Location
    Hollister, CA
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Can you execute a macro or shortcut keystroke within an "IF" function?

    Hello Millz, It worked perfect!!!!!! Thank you once again!!! Ty

  19. #19
    Registered User
    Join Date
    12-12-2013
    Location
    Hollister, CA
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Can you execute a macro or shortcut keystroke within an "IF" function?

    Hello 6String & Millz, you have saved me many, many hours in time and I am deeply grateful. Excelforum is a great website and I would like to contribute to it. But I couldn't find out how to do this. Any suggestions? Ty

+ 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. Can't execute a macro whit text inside procedure header's "()" *Help*
    By Timestamp in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-24-2012, 06:55 AM
  2. function (UDF) to execute "application.CalculateFullRebuild"
    By cg4 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-16-2012, 04:30 PM
  3. How to execute macro requiring an entry on the "save as" menu
    By anmck in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-09-2010, 04:45 PM
  4. Replies: 1
    Last Post: 05-25-2010, 02:25 PM
  5. Excel 2003 should have "multiply multiple cells" macro / shortcut
    By Tommy D in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-20-2005, 05:05 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