Share via

toggle hide cols using shape as button

Anonymous
2023-04-19T17:33:25+00:00

I used something similar years ago but, trying to assign a macro to a shape (used as button). Trying to hide A:D if unhidden but, if it already hidden, unhide them.

Found code using a button but, works differently when using a shape.

Sub Toggle_HIDE()

If Columns("A:D").Hidden = True Then

Columns("A:D").Select

Selection.EntireColumn.Hidden = False 

End If 

Exit Sub 

If Columns("A:D").Hidden = False Then 

Columns("A:D").Select

Selection.EntireColumn.Hidden = True 

    End If 

End Sub

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2023-04-19T17:43:32+00:00

Try this one.

==================

Sub Toggle_HIDE()

If Columns("A:D").Hidden = True Then

Columns("A:D").Select

Selection.EntireColumn.Hidden = False

Exit Sub

End If

If Columns("A:D").Hidden = False Then

Columns("A:D").Select

Selection.EntireColumn.Hidden = True

End If

End Sub

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2023-04-19T17:55:13+00:00

    Thanks!

    When i make my first million.... I'm buying you a Krystal burger WITH cheese!

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2023-04-19T17:40:49+00:00

    Try just

    Sub Toggle_HIDE()

    Columns("A:D").Hidden = Not Columns("A:D").Hidden

    End Sub

    Was this answer helpful?

    0 comments No comments