Multiple VBA Codes on 1 sheet

newbie297

New Member
Joined
Mar 16, 2018
Messages
3
I'm a complete novice with VBA codes, I've added the below to hide columns based on a drop down menu but I also want to hide tabs based on the same drop down menu but have no idea how, any ideas?

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 And Target.Row = 3 And Target.Value = "No" Then
Application.Columns("F").Select
Application.Selection.EntireColumn.Hidden = True
Else
Application.Columns("F").Select
Application.Selection.EntireColumn.Hidden = False
End If

If Target.Column = 2 And Target.Row = 3 And Target.Value = "Yes" Then
Application.Columns("E").Select
Application.Selection.EntireColumn.Hidden = True
Else
Application.Columns("E").Select
Application.Selection.EntireColumn.Hidden = False
End If
End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
To hide a sheet, use:
Code:
ActiveWorkbook.Sheets("your-sheet-name").Visible = xlSheetHidden
You also may also chose xlSheetVeryHidden, which would prevent the sheet from being unhidden through the Excel UI.
 
Upvote 0
Hi,

To hide a sheet :

Code:
Worksheets("SheetName").Visible = xlSheetHidden

To make it visible again :

Code:
Worksheets("SheetName").Visible = xlSheetVisible
 
Upvote 0
Hi & welcome to MrExcel.

Your code can be condensed to this
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Not Target = Range("B3") Then Exit Sub
   Columns("F").Hidden = Target.Value = "No"
   Columns("E").Hidden = Target.Value = "Yes"
   
End Sub
Which sheets do you want to hide/unhide?
 
Upvote 0
When the drop down answer is Yes it hides column E and I also want it to hide sheet 5 which is called "No Multibuy Packing Note"
And when the drop down answer is No It hides column F and I also want it to hide sheet 4 which is called "Multibuy Packing Note"
The code is all on sheet 3

I hope that makes sense.
 
Upvote 0
Try
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Not Target = Range("B3") Then Exit Sub
Columns("F").Hidden = Target.Value = "No"
Columns("E").Hidden = Target.Value = "Yes"
Sheets("No Multibuy Packing Note").Visible = Not Target.Value = "Yes"
Sheets("Multibuy Packing Note").Visible = Not Target.Value = "No"
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,504
Messages
6,125,183
Members
449,212
Latest member
kenmaldonado

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