+ Reply to Thread
Results 1 to 13 of 13

When closing excel remember radio button choice

  1. #1
    Registered User
    Join Date
    03-20-2010
    Location
    Portugal
    MS-Off Ver
    Excel 2019
    Posts
    69

    When closing excel remember radio button choice

    Hi there,

    How can i save the radio button choice and calculate a sum?
    If i press the radio button the sum its ok, but if i close the excel workbook and open it again, the correct radion button is selected but doesnt make the sum requested in the function.

    I had made so far this: (maybe i have to pass the boolean as a parameter to the workbook_open, but i dont know how to do it, and i am confused if the things have to be private or public)

    This code is on: ThisWorkbook

    Please Login or Register  to view this content.
    .
    This code is on: Sheet1

    Please Login or Register  to view this content.
    But it doesnt work when i close the excel and then open it again, as i was explaning,

    Can anyone help me with this problem?
    Thanks
    Last edited by Blue_Wings; 09-14-2011 at 12:55 AM.

  2. #2
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: When closing excel remember radio button choice

    You need to store the value of the option box and then retrieve it when the file is opened (or when the sheet is selected). You can store the value in the workbook, a separate file, or the windows registry. The simplest method is to put it someplace in the workbook (remember to save before closing). If you still need help with this process, let me know and I'll post an example. Thanks!
    -Greg If this is helpful, pls click Star icon in lower left corner

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,330

    Re: When closing excel remember radio button choice

    Hi Blue_Wings,

    I've run into this topic before. My old solution was to take some not-used cell and put a value in it that reflected which radio button was clicked. When a radio button is selected, I'd simply plug a number in this cell to remember it. When the workbook was closed the value of this cell is saved also. When the workbook is opened you will need routines to look at the not-used cell and reset your radio buttons to what they were when last saved.

    A few months ago I found Range Names that may do the same thing without needing a cell. After looking they are called Named Constants in http://pubs.logicalexpressions.com/p...cle.asp?id=281

    You could create a Named Constant that reflects which radio button instead of using a cell. The constant will be saved when you save the workbook.

    Attach a short example with radio buttons on it, if you need, and we can explore the code to make all this high powered theory work.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    03-20-2010
    Location
    Portugal
    MS-Off Ver
    Excel 2019
    Posts
    69

    Re: When closing excel remember radio button choice

    Quote Originally Posted by gjlindn View Post
    You need to store the value of the option box and then retrieve it when the file is opened (or when the sheet is selected). The simplest method is to put it someplace in the workbook (remember to save before closing). If you still need help with this process, let me know and I'll post an example. Thanks!
    Can you post an example?
    Remember to save before closing? What do you mean? Does not the excel always ask to save before closing as usual ?
    Thanks

  5. #5
    Registered User
    Join Date
    03-20-2010
    Location
    Portugal
    MS-Off Ver
    Excel 2019
    Posts
    69

    Re: When closing excel remember radio button choice

    Quote Originally Posted by MarvinP View Post
    Hi Blue_Wings,

    I've run into this topic before. My old solution was to take some not-used cell and put a value in it that reflected which radio button was clicked. When a radio button is selected, I'd simply plug a number in this cell to remember it. When the workbook was closed the value of this cell is saved also. When the workbook is opened you will need routines to look at the not-used cell and reset your radio buttons to what they were when last saved.

    A few months ago I found Range Names that may do the same thing without needing a cell. After looking they are called Named Constants in http://pubs.logicalexpressions.com/p...cle.asp?id=281

    You could create a Named Constant that reflects which radio button instead of using a cell. The constant will be saved when you save the workbook.

    Attach a short example with radio buttons on it, if you need, and we can explore the code to make all this high powered theory work.
    Hi MarvinP, i would like to test your version as well, the method using cells works,i had tried before but it's a last resort solution as you said. If you can put inside my excel file that example working with the Named Constant i would appreciated

    Thanks.
    Attached Files Attached Files

  6. #6
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: When closing excel remember radio button choice

    Here's an example using the workbook you uploaded. This uses Marvin's suggested method of storing it as a constant name (I called the name OptionA). You'll notice the VBA has some changes/additions which include the name. The workbook should prompt you to save before closing--I was only reminding you to do so.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by gjlindn; 09-11-2011 at 01:04 AM.

  7. #7
    Registered User
    Join Date
    03-20-2010
    Location
    Portugal
    MS-Off Ver
    Excel 2019
    Posts
    69

    Re: When closing excel remember radio button choice

    Hi gjlindn,

    Thanks for the help. At first when i downloaded the attached excel file and i had run it it gives an error in the debug manager, but i closed it and openit again and now its ok.
    Now i copied the code to my excel file without the line of the variable "Selection" because i dont need it anymore, but gives me an error.

    Run-time error 1004
    Aplication-defined or object-defined error

    and the error seems to be on these lines:

    ActiveWorkbook.Names("OptionA").RefersTo = "TRUE"

    and

    ActiveWorkbook.Names("OptionA").RefersTo = "FALSE"

    Do i need to creat it first? If so how?

    Please Login or Register  to view this content.
    And i had put it also the code inside ThisWorkbook:

    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: When closing excel remember radio button choice

    You are correct; you have to create the named constant first. Here you will find step by step instructions for doing so:
    http://www.dummies.com/how-to/conten...xcel-2007.html

  9. #9
    Registered User
    Join Date
    03-20-2010
    Location
    Portugal
    MS-Off Ver
    Excel 2019
    Posts
    69

    Re: When closing excel remember radio button choice

    Constant created
    Now i am dealing with another problem, while i am working on the sheet, if i change the value of the cell "H29" it doesnt refresh the result aotmatically, i have to press the radio button again to refresh the result.

    How do i solve that problem when i open the workbook, change sheet or change cell value?

    I guess i will need these sub's :

    Please Login or Register  to view this content.
    when i change from another sheet to this one.
    Please Login or Register  to view this content.
    when i open the excel file.
    Please Login or Register  to view this content.
    when the cell value has changed

    But can you tell me if these ones ane correct? And how to refresh in this whole cases?
    Thanks.
    Last edited by Blue_Wings; 09-13-2011 at 03:55 AM.

  10. #10
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: When closing excel remember radio button choice

    Does pressing F9 update the calculation? If so, automatic calculations are turned off and can be turned on in the Excel Options. If you want the option buttons to change when a cell value changes, they should probably have their source value set to a cell rather than a named constant. I don't have Excel 2007 at work, but if you repost your workbook I can at least review what you have later tonight (if the above doesn't work/make sense). Thanks!

  11. #11
    Registered User
    Join Date
    03-20-2010
    Location
    Portugal
    MS-Off Ver
    Excel 2019
    Posts
    69

    Re: When closing excel remember radio button choice

    F9 does the automatic calculation in the cells, but because i have inside the
    Please Login or Register  to view this content.
    the
    Please Login or Register  to view this content.
    the "TotalPayment" doesnt refresh if i change the value in the cell H29 in "PaymentA".
    You can use the example that you gave to me in reply nš 6 OptionButton.xlsm it fits the same problem.
    Thanks.
    Last edited by Blue_Wings; 09-13-2011 at 03:56 AM.

  12. #12
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: When closing excel remember radio button choice

    When the cell value changes you should run the update...but it sounds like you may need to be using formulas instead of hard-coded values. Personally I try to avoid worksheet change events when possible. Attached is a non-vba method to do what you want. This uses two named ranges (OptionBtnA and OptionBtnB). They're assigned to the linked property of each Option Button.
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    03-20-2010
    Location
    Portugal
    MS-Off Ver
    Excel 2019
    Posts
    69

    Re: When closing excel remember radio button choice

    Quote Originally Posted by gjlindn View Post
    When the cell value changes you should run the update...but it sounds like you may need to be using formulas instead of hard-coded values. Personally I try to avoid worksheet change events when possible. Attached is a non-vba method to do what you want. This uses two named ranges (OptionBtnA and OptionBtnB). They're assigned to the linked property of each Option Button.
    I get it, I think it couldnt be easier and simpler than that, no need to complicate.
    Thanks!

+ 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