I need help creating a macro to hide and unhide several non-adjacent columns based on a value in cell D2.
I need help creating a macro to hide and unhide several non-adjacent columns based on a value in cell D2.
Which columns do you want to hide or unhide and what value in D2 determines whether to hide or unhide?
Cell D2 will contain a label, either "City" or "State". If the value is "City", I want columns Q, R, & S to be hidden. If the value is "State", I want columns Z, AA, and AB to be hidden.
Maybe:
![]()
Sub MistiM() Select Case Range("D2").Value Case Is = "City" Columns("Q:S").Hidden = True Columns("Z:AB").Hidden = False Case Is = "State" Columns("Z:AB").Hidden = True Columns("Q:S").Hidden = False End Select End Sub
This works perfectly. Thank you so much!
You're welcome. Glad to help out, and thanks for the feedback. Please comply with Forum Rule No. 9.
9. Acknowledge the responses you receive, good or bad. If your problem is solved, please say so clearly, and mark your thread as Solved: Click Thread Tools above your first post, select "Mark your thread as Solved". Or click the Edit button on your first post in the thread, Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Dropdown option or Edit button will not appear -- ask a moderator to mark it.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks