VBA help

Mike89

New Member
Joined
Feb 20, 2014
Messages
16
Hi,

I'm trying to combine multiple VBA codes but i'm having trouble.

I currently have;

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("b26").Value = "Hide" Then
Columns("b:m").EntireColumn.Hidden = True
Else
Columns("b:m").EntireColumn.Hidden = False
End If
End Sub

but I need to combine the above with these;

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("n26").Value = "Hide" Then
Columns("n:y").EntireColumn.Hidden = True
Else
Columns("n:y").EntireColumn.Hidden = False
End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("z26").Value = "Hide" Then
Columns("z:ak").EntireColumn.Hidden = True
Else
Columns("z:ak").EntireColumn.Hidden = False
End If
End Sub

and so on...

Many thanks in advance
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Maybe something like
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.Columns.EntireColumn.Hidden = False
If Range("b26").Value = "Hide" Then Columns("b:m").EntireColumn.Hidden = True
If Range("n26").Value = "Hide" Then Columns("n:y").EntireColumn.Hidden = True
If Range("z26").Value = "Hide" Then Columns("z:ak").EntireColumn.Hidden = True
End Sub
 
Upvote 0
How will you remove the 'hide' once the columns have been hidden. ie you want them unhidden again.
 
Upvote 0
Thanks!

Your suggestion works!

Steve Its data that is also logged on a hidden sheet but i wont need to see again on the current sheet.
 
Upvote 0

Forum statistics

Threads
1,207,278
Messages
6,077,494
Members
446,286
Latest member
ropebender

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