+ Reply to Thread
Results 1 to 9 of 9

VBA Button Undo option

  1. #1
    Registered User
    Join Date
    11-21-2018
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    2011
    Posts
    4

    VBA Button Undo option

    Hi guys,

    I am completely new this forum, hope I can learn a lot from you guys especially when it comes to VBA.

    I have a simple working button which will hide some rows within a range if a column value is empty or 0.

    For the working code, see below:

    Sub HideUnhidej()
    Dim cell As Range
    For Each cell In Range("D8:D18, D23:D29")
    If IsNumeric(cell) Then
    cell.EntireRow.Hidden = cell.Value = 0
    End If
    Next cell
    End Sub

    What I want to achieve is that once I click the same button again, the hidden rows will be unhidden again so I can edit them if necessary.

    I am struggling with an Else script but so far I did not result in the solution. I hope anybody could help me out.


    Thank you in advance and kind regards,

    Wesley

  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,907

    Re: VBA Button Undo option

    Does it really need to be the same button? It makes the code more complicated than just using separate routines.
    Rory

  3. #3
    Registered User
    Join Date
    11-21-2018
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    2011
    Posts
    4
    Quote Originally Posted by rorya View Post
    Does it really need to be the same button? It makes the code more complicated than just using separate routines.
    Hi Rorya,

    Thanks for your reply! I prefer using the same button but a seperate button would be a great temporary alternative in search for the final answer.

    Thanks again!

  4. #4
    Valued Forum Contributor dotchiejack's Avatar
    Join Date
    05-21-2015
    Location
    Antwerp,Belgium
    MS-Off Ver
    2016
    Posts
    507

    Re: VBA Button Undo option

    Use a togglebutton and this code
    Please Login or Register  to view this content.
    See working example
    Attached Files Attached Files
    Click the * Add Reputation below to say thanks.

  5. #5
    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,907

    Re: VBA Button Undo option

    To unhide all you need is:

    Please Login or Register  to view this content.
    Though, on reflection, all you need for a toggling routine would be something like:

    Please Login or Register  to view this content.
    Last edited by rorya; 11-21-2018 at 05:57 AM.

  6. #6
    Registered User
    Join Date
    11-21-2018
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    2011
    Posts
    4

    Re: VBA Button Undo option

    Wow dotchiejack, works amazing! Thank you both so much for taking the effort to help me out!

  7. #7
    Valued Forum Contributor dotchiejack's Avatar
    Join Date
    05-21-2015
    Location
    Antwerp,Belgium
    MS-Off Ver
    2016
    Posts
    507

    Re: VBA Button Undo option

    Glad to help.
    Have a nice day

  8. #8
    Registered User
    Join Date
    11-21-2018
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    2011
    Posts
    4

    Re: VBA Button Undo option

    Quote Originally Posted by dotchiejack View Post
    Glad to help.
    Have a nice day
    Hi Dotchiejack,

    I have a little challenge regarding the code. It works great on my Office 2014 with Windows as an operation system. However, at the office most of the colleagues work with 2011 on MacOS which does not support ActiveX. Is there any workaround to also make it workable for them?

    Thank you again!

  9. #9
    Valued Forum Contributor dotchiejack's Avatar
    Join Date
    05-21-2015
    Location
    Antwerp,Belgium
    MS-Off Ver
    2016
    Posts
    507

    Re: VBA Button Undo option

    I should use a (form)checkbox.
    I named the checkbox Check1
    See attached.
    Attached Files Attached Files

+ 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. Hide option buttons based on other option button
    By monfos in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-21-2016, 05:16 PM
  2. Undo Button
    By keithy397 in forum Excel General
    Replies: 2
    Last Post: 09-16-2016, 10:19 AM
  3. Using vba code with undo option
    By Masa1989 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-22-2015, 03:08 AM
  4. Replies: 2
    Last Post: 08-15-2013, 12:25 PM
  5. Userform Option Button to Show/Hide Another Option Button on same Userform
    By R_S_6 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-26-2010, 09:44 AM
  6. [SOLVED] keep source formatting is not an option in paste option button
    By Tina in forum Excel General
    Replies: 0
    Last Post: 02-20-2006, 06:00 PM
  7. Undo button??
    By Bruise in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-18-2006, 08:15 PM

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