Macro to toggle columns

Matt Dymond 0 Reputation points
2024-01-05T18:17:58.92+00:00

In the past I have used a macro to toggle columns. I created a new spread sheet and have tried using the same macro. I'm doing something wrong.

I'm new to this, if someone can direct me in the right direction.

[Image

](https://filestore.community.support.microsoft.com/api/images/156db528-2eeb-461b-8cbb-eda5bfb65996?upload=true&fud_access=wJJIheezUklbAN2ppeDns8cDNpYs3nCYjgitr%2BfFBh2dqlqMuW7np3F6Utp%2FKMltnRRYFtVjOMO5tpbpW9UyRAwvLeec5emAPixgq9ta07Dgnp2aq5eJbnfd%2FU3qhn54ZZzxUXCorpJSnWHy8AP1xii59jLek%2BIYSkOvRb9N9a0S3eQxg4mOclmwn%2FXrTQ87kXN3LfFU74kCOBAyasKCPMghu1YUH7qujORSJuymh7vHPEKkZbcMjYVoQ8A0Y9e6HknXNLUE9siqWLVmCKctRNB%2FNweR5xDOERYiBd9N8fpvfrJXFbOltg9Y4D8CQP%2Bcq5BdIvTQXG1yk%2FZuNgGe6Jxgb8B8fMA9T6z4bP3%2Fiopz3bQsOoIoEeOuL%2BqwIF8qciiZcjPOXHXTTCd%2BQkudUrvZFxyrHPWzPtW9yaGG%2F30%3D"filestore.community.support.microsoft.com")

[Image

](https://filestore.community.support.microsoft.com/api/images/d85315bd-6e46-419e-823c-0668891bac43?upload=true&fud_access=wJJIheezUklbAN2ppeDns8cDNpYs3nCYjgitr%2BfFBh2dqlqMuW7np3F6Utp%2FKMltnRRYFtVjOMO5tpbpW9UyRAwvLeec5emAPixgq9ta07Dgnp2aq5eJbnfd%2FU3qhn54ZZzxUXCorpJSnWHy8AP1xii59jLek%2BIYSkOvRb9N9a0S3eQxg4mOclmwn%2FXrTQ87kXN3LfFU74kCOBAyasKCPMghu1YUH7qujORSJuymh7sJMCgAV3sDrXzkAFTqyrtUvi3luBsRazLEG8JIsCAr9ZJwp%2FTXxO7ZlK6rWiuaPkqEGGjbKrJMx70L9aKjbGf13SLuUKeY%2FQ1WFRIM5bA4tkiAc%2BQUOelL5%2FbN3T3oeFdSkQQZyHFhpthT%2Bc8Caq9s6TvwP21RgyjWmio96eTUbqPN10dubWMA58%2BPAc7E%2BFM%3D"filestore.community.support.microsoft.com")

I want to hide columns G, K, O, S, W, AA, and, AE

After completing this my next step is to add a check box that will hide rows. What do I need to do to convert the macro to toggle rows?

Thank you in advance.

Microsoft 365 and Office | Development | Other
Microsoft 365 and Office | Excel | For business | Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 122.6K Reputation points
    2024-01-05T20:46:14.8866667+00:00

    Try to fix the code in this manner:

    Sub CheckBox1_Click()
    
        toggleColumns
    
    End Sub
    
    
    Sub toggleColumns()
    
        Dim ws As Worksheet
    
        ... etc ...
    
    End Sub
    

    To hide a row, try this: ws.Rows(20).Hidden = shouldBeHidden.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.