Hide/Unhide Toggle

Nush1981

Board Regular
Joined
Oct 24, 2006
Messages
92
Please could someone provide me with the VBA to 'toggle' between HIDING and UNHIDING columns within one macro

e.g. toggle between this hiding and unhiding the following

Sub HideColumns()

Range("G:G,I:I,AB:AV").Activate
Selection.EntireColumn.Hidden = True

End Sub

Thanks
 
Because of this:

Code:
    If ccell.EntireRow.Hidden = True Then cell.EntireRow.Hidden = False

When the If statement is on one line like that you do not need an End If. So, the 'Else' statement is essentially stranded outside of any If statement.

Edit: Also, your use of the For/Next is a bit messed up there, too. Try:
Code:
For Each cell In Range("A8:A207")
    If cell.EntireRow.Hidden = True Then
        cell.EntireRow.Hidden = False
    Else
        If cell.Value = "xxxxx" Then
            cell.EntireRow.Hidden = True
        End If
    End If
Next cell
 
Last edited:
Upvote 0
THANK YOU THANK YOU THANK YOU THANK YOU!


I was trying so many different permutations of the code, got as close as getting everything to work unless I actually changed the value from "xxxxx". Yours, however, works flawlessly!

Thanks again!

So, so long as I break the if/then statements up with a line break (after then), I can insert the Else statements? Cool!
 
Upvote 0
"Every trick I know, I learned on this board."

The code mortgageman posted is in the first chapter (Lesson 1) of a Microsoft book I read when first learning VBA (Step By Step Ms Excel 97 VB).

So there are other sources for learning "tricks". :cool:
 
Upvote 0
So, so long as I break the if/then statements up with a line break (after then), I can insert the Else statements? Cool!

Well, it can get even more confusing than that. You can even do If Else all on one line :)

Code:
For Each cell In Range("A8:A207")
    If cell.EntireRow.Hidden = True Then cell.EntireRow.Hidden = False Else If cell.Value = "xxxxx" Then cell.EntireRow.Hidden = True
Next cell
 
Upvote 0
"Every trick I know, I learned on this board."

The code mortgageman posted is in the first chapter (Lesson 1) of a Microsoft book I read when first learning VBA (Step By Step Ms Excel 97 VB).

So there are other sources for learning "tricks". :cool:

:huh: I never said there were not. I was just pointing out a great feature of this board.
 
Upvote 0
"I never said there were not. I was just pointing out a great feature of this board."

Just thought it strange that you have not learnt any "tricks" from anywhere other than this board.<!-- / message --><!-- sig -->
 
Upvote 0
"I never said there were not. I was just pointing out a great feature of this board."

Just thought it strange that you have not learnt any "tricks" from anywhere other than this board.<!-- / message --><!-- sig -->

I suspect that this discussion is not only OT but better for the lounge, but anyway:

It has been decades since I worked in any sort of software coding. I moved over into finance and then sales of mortgages. I use Excel for my business, and the only book I read was Walkenback's book. I have found that this board is a far better resource for someone like me - self taught - than anywhere else I can find. For those who have had a more "formal education" (whatever that is) in Excel, this board may not be as valuable - though I suspect that even that is not true.

At the end of day, it would seem that how is less important than the fact itself - except for the requirement to give credit where it is due.
 
Last edited:
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top