+ Reply to Thread
Results 1 to 19 of 19

Toggle button to assign / unassign value to a cell

  1. #1
    Registered User
    Join Date
    12-13-2021
    Location
    Minnesota
    MS-Off Ver
    MS Office 365
    Posts
    9

    Toggle button to assign / unassign value to a cell

    Hello,

    I am a novice to excel formulas and VBA coding and have been researching a way to use a toggle button in one cell to assign a value in another cell. I am using the "show code" of the toggle to enter a formula that will assign a price value when "on" and assign a 0 value when "off".

    The formula I am using is:

    Please Login or Register  to view this content.
    When I click the toggle button, it activates a price, but once I click it again it locks the value and does not allow the toggle to operate further. Example, click the toggle button, cell K2 activates a value of $1.00. Click the toggle again, the toggle locks and the value locks to $0.

    Am I missing a part of the formula that is causing this error to occur?

    Thank you in advance for any ideas or resolution.

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,918

    Re: Toggle button to assign / unassign value to a cell

    It works fine for me so I suspect something else is causing the problem. You could just forgo the code and make the LinkedCell property of the togglebutton the address of the cell you want. You'll get TRUE/FALSE rather than 1/0 but you can probably use that just as easily.
    Rory

  3. #3
    Registered User
    Join Date
    12-13-2021
    Location
    Minnesota
    MS-Off Ver
    MS Office 365
    Posts
    9

    Re: Toggle button to assign / unassign value to a cell

    The True/False default doesn't fit my application. I need an assigned dollar value down a column of toggles.

    Column J is the toggle buttons, Column K is the price = either active or inactive. The end game is to tally the active values to total a package price.

    I'll try it again, but I have tried 3 versions of code and each time I get the error where it locks the toggle and the "false" value.

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,918

    Re: Toggle button to assign / unassign value to a cell

    It shouldn't be an issue but if it's supposed to be a number, you shouldn't put it in quotes:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    12-13-2021
    Location
    Minnesota
    MS-Off Ver
    MS Office 365
    Posts
    9

    Re: Toggle button to assign / unassign value to a cell

    It doesn't seem to be an issue with the formula, perhaps it's an issue with the toggle setting?

    If I delete the formula, the toggle works by clicking so it goes on/off and returns the value "True" or "False" in the cell. When I enter the formula, the toggle gets stuck.

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,918

    Re: Toggle button to assign / unassign value to a cell

    What formula? Do you mean the code?

    You should not be using both the code and the LinkedCell. It's one or the other.

  7. #7
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    252

    Re: Toggle button to assign / unassign value to a cell

    Quote Originally Posted by BMF5000 View Post
    It doesn't seem to be an issue with the formula, perhaps it's an issue with the toggle setting?

    If I delete the formula, the toggle works by clicking so it goes on/off and returns the value "True" or "False" in the cell. When I enter the formula, the toggle gets stuck.
    From what I understand K2 has a formula in it? If that's the case then that is why, as you're replacing the formula with an integer and erasing the original formula.

  8. #8
    Registered User
    Join Date
    12-13-2021
    Location
    Minnesota
    MS-Off Ver
    MS Office 365
    Posts
    9

    Re: Toggle button to assign / unassign value to a cell

    J2 cell is the toggle, I am using design mode to add the code to populate cell K2.

    Attachment 759180

    Oddly, I can use the same code in J2 and tell it to populate K4 and it works. So now I'm really unsure why it's locking the toggle.

    I don't have a formula in the K2, only the J2 toggle settings has the code. Sorry for the confusion

  9. #9
    Registered User
    Join Date
    12-13-2021
    Location
    Minnesota
    MS-Off Ver
    MS Office 365
    Posts
    9

    Re: Toggle button to assign / unassign value to a cell

    Well, I can circumvent the issue by moving the target cell to another column. Not how I want it to look, but at least it works.

    Attachment 759181

    Attachment 759182

  10. #10
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    252

    Re: Toggle button to assign / unassign value to a cell

    Quote Originally Posted by BMF5000 View Post
    Well, I can circumvent the issue by moving the target cell to another column. Not how I want it to look, but at least it works.

    Attachment 759181

    Attachment 759182
    Attachments don't work unless you follow the instructions in the yellow banner at the top unfortunately, so I can't see what is attached.

    Could you upload a sample of the workbook? To be honest, your question doesn't entirely make sense as you're talking about formulas which aren't really relevant to VBA.

  11. #11
    Registered User
    Join Date
    12-13-2021
    Location
    Minnesota
    MS-Off Ver
    MS Office 365
    Posts
    9

    Re: Toggle button to assign / unassign value to a cell

    OK Trying to attach the example workbook.
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    252

    Re: Toggle button to assign / unassign value to a cell

    Quote Originally Posted by BMF5000 View Post
    OK Trying to attach the example workbook.
    Now I am even more confused because the attached example works perfectly. Nothing gets locked, everything toggles as it should?

  13. #13
    Registered User
    Join Date
    12-13-2021
    Location
    Minnesota
    MS-Off Ver
    MS Office 365
    Posts
    9

    Re: Toggle button to assign / unassign value to a cell

    That is where I am at now, I moved the target cell to L instead of K, so it works like I said, it's just not how I wanted to display it.

    Now I'm trying to apply that code to each toggle button so that Toggle J2 goes to L2, J3 to L3 and so forth. Having trouble with the code for each toggle.

    Please Login or Register  to view this content.

  14. #14
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,918

    Re: Toggle button to assign / unassign value to a cell

    If you're using the cell link anyway, why not put a formula like

    =IF(K2,79.99,0)

    in L2 and skip the code altogether?

  15. #15
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    252

    Re: Toggle button to assign / unassign value to a cell

    Can I ask, is there a reason you are using Toggle buttons instead of regular buttons? ActiveX controls are yuk, hence why it is a dead format.

  16. #16
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,918

    Re: Toggle button to assign / unassign value to a cell

    It does work if you don't use both the code and LinkedCell, as I mentioned earlier.

    The comment about ActiveX is well-founded though!

  17. #17
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    252

    Re: Toggle button to assign / unassign value to a cell

    Take a look at my interpretation without the ActiveX control. The button can be copy and pasted where you want it, there's no need for additional code as the button looks at its own location and offsets the cell. (My example is on Sheet 1)
    Attached Files Attached Files
    Last edited by PrizeGotti; 12-13-2021 at 12:16 PM.

  18. #18
    Registered User
    Join Date
    12-13-2021
    Location
    Minnesota
    MS-Off Ver
    MS Office 365
    Posts
    9

    Re: Toggle button to assign / unassign value to a cell

    Quote Originally Posted by PrizeGotti View Post
    Can I ask, is there a reason you are using Toggle buttons instead of regular buttons? ActiveX controls are yuk, hence why it is a dead format.
    To be honest it's just what came up through a web search in my attempt to learn how to achieve the desired effect.

    It seems you have a much easier way to accomplish this, I'm just not familiar with using "Regular Buttons". I'd like to know how you created that in your sheet 1 example. You have both made a very valid point that I seem to be over-complicating this.

  19. #19
    Registered User
    Join Date
    12-13-2021
    Location
    Minnesota
    MS-Off Ver
    MS Office 365
    Posts
    9

    Re: Toggle button to assign / unassign value to a cell

    I did solve this issue and thank you both for your help. I did end up just using a simple if statement tied to the toggle button and hid the true/false column.

+ 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. [SOLVED] Assign Code to Shapes Instead of Toggle Button
    By crazyforexcel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-17-2020, 12:01 PM
  2. How do I insert a toggle button to cover a cell range?
    By Yellowchalkie in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-22-2019, 07:32 PM
  3. [SOLVED] how do i make a toggle button change other toggle buttons value to false
    By kevinu in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-10-2018, 04:19 PM
  4. Radio Button to toggle YES or NO based on a cell value
    By egrospe17 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-10-2016, 11:22 PM
  5. Replies: 1
    Last Post: 02-13-2014, 10:55 PM
  6. Toggle Button set to true if cell is equal to text
    By ravergirl7216 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-29-2010, 02:03 PM
  7. [SOLVED] Place the caption of a toggle button into a cell
    By [email protected] in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-12-2005, 12:07 AM

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