+ Reply to Thread
Results 1 to 9 of 9

macro to toggle cell value

  1. #1
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Exclamation macro to toggle cell value

    could anyone here provide simple macro i can assign to a button that will togglethe value of a specified cell to 1,0,or true/false,black/white or similar
    pretty please!

    oh dear now ive searched i found several options already availiabe,option button /scroll bar.
    so simple really! so no code needed here thanx
    Last edited by martindwilson; 10-18-2007 at 11:14 AM.

  2. #2
    Forum Contributor wmorrison49's Avatar
    Join Date
    09-25-2007
    Posts
    267
    You could just write something that sees if a cell is one thing and if it is, switch it to the other. For example, if the cell is A1 and you wanted to toggle between 1 and 0, you could have:

    Range("A1").Select
    If ActiveCell = 1 Then
    ActiveCell = 0
    Else
    ActiveCell = 1
    End If
    Is that what you mean?

  3. #3
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320
    thanx
    Iassigned that to a button and it works a treat! toggles a1 1 or zero.
    thats now stored in my "excel how did i do that folder "for future reference.

  4. #4
    Forum Contributor wmorrison49's Avatar
    Join Date
    09-25-2007
    Posts
    267
    Haha, I have one of those folders too. Glad it worked

  5. #5
    Registered User
    Join Date
    11-28-2020
    Location
    Rochester NY
    MS-Off Ver
    2019
    Posts
    4

    Re: macro to toggle cell value

    I have a conditional formatting set determined by the value of a cell being TRUE/FALSE.
    I added a button to the quick toolbar using that macro, which works wonderfully. But, when I run it, the
    sheet scrolls up to the cell. How can I eliminate that so it stays where I was? Thanks

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,935

    Re: macro to toggle cell value

    Quote Originally Posted by SESchmidt View Post
    I have a conditional formatting set determined by the value of a cell being TRUE/FALSE.
    I added a button to the quick toolbar using that macro, which works wonderfully. But, when I run it, the
    sheet scrolls up to the cell. How can I eliminate that so it stays where I was? Thanks
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  7. #7
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,527

    Re: macro to toggle cell value

    If you want to save some space for future keep sakes, either one will do.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,527

    Re: macro to toggle cell value

    @AliGW
    The answer was to martindwilson!

    Re: "thats now stored in my "excel how did i do that folder "for future reference."
    In answer to this, I wrote what I wrote.

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: macro to toggle cell value

    I have reinstated the post.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ 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