+ Reply to Thread
Results 1 to 12 of 12

Macro to unhide columns, call a macro, then revert columns to previous state.

Hybrid View

kjg Macro to unhide columns, call... 07-17-2014, 08:46 AM
Olly Re: Macro to unhide columns,... 07-17-2014, 09:15 AM
kjg Re: Macro to unhide columns,... 07-17-2014, 09:20 AM
Olly Re: Macro to unhide columns,... 07-17-2014, 09:23 AM
kjg Re: Macro to unhide columns,... 07-17-2014, 09:37 AM
Olly Re: Macro to unhide columns,... 07-17-2014, 09:42 AM
kjg Re: Macro to unhide columns,... 07-17-2014, 09:49 AM
Olly Re: Macro to unhide columns,... 07-17-2014, 09:51 AM
kjg Re: Macro to unhide columns,... 07-17-2014, 10:02 AM
Olly Re: Macro to unhide columns,... 07-17-2014, 09:49 AM
kjg Re: Macro to unhide columns,... 07-17-2014, 09:57 AM
Olly Re: Macro to unhide columns,... 07-17-2014, 10:08 AM
  1. #1
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    205

    Red face Macro to unhide columns, call a macro, then revert columns to previous state.

    Hi Guys

    I have on sheet1 a number (72 at the moment) of Form CheckBoxes.

    In simple terms:
    I would like a macro to look at each CheckBox and remember its state (Checked or Unchecked)

    Then, go through and Check All checkboxes

    Call MyMacro

    Once MyMacro is complete (Filtering & Printing)

    Revert the checkboxes to their original state.

    The purpose of the checkboxes:

    When Checked column on sheet2 is UnHidden
    When UnChecked column on sheet2 is Hidden

    Or,

    UnHide All columns on sheet2, run MyMacro, then “re-hide” the columns that were previously hidden.

    TIA
    Keith

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Macro to unhide columns, call a macro, then revert columns to previous state.

    Form or ActiveX checkboxes?
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    205

    Re: Macro to unhide columns, call a macro, then revert columns to previous state.

    Hi Olly,

    As mentioned above, I believe they are form controls.

    Regards,
    Keith

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Macro to unhide columns, call a macro, then revert columns to previous state.

    Sorry, missed that!

    Okay, here you go:
    Sub foo()
    Dim i As Integer, vCBState() As Variant
    
    With Sheet1
        ReDim vCBState(1 To .CheckBoxes.Count)
        
        'Save Checkbox Values
        For i = 1 To .CheckBoxes.Count
            vCBState(i) = .CheckBoxes(i).Value
        Next i
        
        'Tick all Checkboxes
        For i = 1 To .CheckBoxes.Count
            .CheckBoxes(i).Value = 1
        Next i
        
        'DO STUFF
        MsgBox "Ready to do your other code here", vbInformation + vbOKOnly, "XLSM"
        
        'Restore Checkbox Values
        For i = 1 To .CheckBoxes.Count
            .CheckBoxes(i).Value = vCBState(i)
        Next i
        
    End With
    End Sub
    Should all make sense...

  5. #5
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    205

    Re: Macro to unhide columns, call a macro, then revert columns to previous state.

    WoW, that was quick Olly, thanks.

    It does "what it says on the tin", it checks all checkboxes and reverts to the previous state. Unfortunatley it dosn't Hide and UnHide the columns on sheet2.

    Any ideas why?
    Keith

  6. #6
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Macro to unhide columns, call a macro, then revert columns to previous state.

    Right - so the checkboxes are actually irrelevant, you want to store hidden state of columns in Sheet2, unhide them all, do stuff, then restore hidden state, is that right?

  7. #7
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    205

    Re: Macro to unhide columns, call a macro, then revert columns to previous state.

    Yea, sounds about right, have another read of my first post, it may through some light.

    Cheers,
    Keith

  8. #8
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Macro to unhide columns, call a macro, then revert columns to previous state.

    Quote Originally Posted by kjg View Post
    Yea, sounds about right, have another read of my first post, it may through some light.

    Cheers,
    Keith
    I read it, several times. The requirement is still ambiguous... You ask for checkboxes states to be stored and changed, when actually they are irrelevant to what you really want to do?

    Let me know if second attempt does what you thought you asked for.....

  9. #9
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    205

    Re: Macro to unhide columns, call a macro, then revert columns to previous state.

    Sorry if it was ambiguous, I thought the line:>

    Or,

    UnHide All columns on sheet2, run MyMacro, then “re-hide” the columns that were previously hidden.

    would have explained it.

    Anyway, we got there, but point taken, I need to be clear as to what I require.

    Thank You

  10. #10
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Macro to unhide columns, call a macro, then revert columns to previous state.

    If that is what you want, then use thisL
    Sub bar()
    Dim i As Integer, j As Integer, vColState() As Variant
    
    With Sheet2
        j = .UsedRange.Columns.Count
        ReDim vColState(1 To j)
        
        'Save Column hidden state, and unhide
        For i = 1 To j
            vColState(i) = .Columns(i).Hidden
            .Columns(i).Hidden = False
        Next i
        
        'DO STUFF
        MsgBox "All columns unhidden, ready to do your other code here", vbInformation + vbOKOnly, "XLSM"
        
        'Restore Column hidden state
        For i = 1 To j
            .Columns(i).Hidden = vColState(i)
        Next i
        
    End With
    End Sub

  11. #11
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    205

    Thumbs up Re: Macro to unhide columns, call a macro, then revert columns to previous state.

    Olly, thank you so much, its working exactly as required.

    I think this has been the fastest Q & A "with" a solution I have ever had.

    Thank You very much.

  12. #12
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Macro to unhide columns, call a macro, then revert columns to previous state.

    No worries - glad we got it working the way you actually wanted

    Thanks for the feedback.

+ 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] Unhide columns based on the previous column's value
    By dumbom in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-07-2012, 08:20 AM
  2. Replies: 0
    Last Post: 08-14-2012, 04:47 PM
  3. [SOLVED] Can VB Save hidden/grouped columns state, unhide all, then restore columns to saved state
    By JTwrk in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-27-2012, 02:54 PM
  4. Hide or unhide columns with one macro
    By simonsmith in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-23-2008, 10:13 PM
  5. [SOLVED] Utility to revert accidently over written file back to previous state?
    By Nate Goulet in forum Excel General
    Replies: 3
    Last Post: 11-15-2005, 06:15 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