Hiding sheets based on a value in a cell

JessicaKinnear

New Member
Joined
Jan 6, 2021
Messages
25
Office Version
  1. 365
Platform
  1. Windows
Hey, I'm looking for some help on a VBA code.

I basically have a sheet named 'INPUTS-BULDING DETAILS' then I have 12 sheets named 'Tenant - 1', 'Tenant - 2' etc. all the way up to 12 which I want to hide if a certain cell doesn't contain a value.

On my inputs tab I want to be able to code so that if cell F36 has no value then hide sheet 'Tenant -1', if cell F37 has no value then hide sheet 'Tenant - 2', then this to repeat all the way up to cell F47 and sheet 'tenant - 12'

Does anyone know the correct code for this (I am a complete beginner when it comes to coding so think code for dummies :))

Thank you in advance!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
In that case make sure the the "blank" cells are totally empty.
 
Upvote 0
thanks for your reply, this didn't seem to work either
Hi, according to your explanation a VBA demonstration to paste to the input worksheet module :​
VBA Code:
Sub Demo1()
    Dim V, R%
        V = [IF({1},TRIM(F36:F47)>"")]
    For R = 1 To 12:  Sheets("Tenant - " & R).Visible = V(R, 1):  Next
End Sub

Jessica,​
did you ever try post #9 ?​
Hey, apologies i thought i replied. i did try it but this code also didn't work
 
Upvote 0
As both codes work on helpers side maybe it's time to link your workbook on a files host website like dropbox for example …​
 
Upvote 0
Ok, how about
VBA Code:
Sub Jessica()
   Dim i As Long
  
   For i = 1 To 12
      Sheets("Tenant - " & i).Visible = Sheets("INPUTS-BULDING DETAILS").Range("F" & i + 35) <> ""
   Next i
End Sub
Hey, I've finally managed to get this to work. Thank you for your help. However my only issue now is that to get it to work I have to run the code. What I would like to happen is that if for example if I put a value in cell F36 I want it to hide the tenant 1 tab straight away instead of me having to press run code for it to happen. Is that possible?
 
Upvote 0
If you want it to be automatic, try
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("F36:F47")) Is Nothing Then
      Sheets("Tenant - " & Target.Row - 35).Visible = Target.Value <> ""
   End If
End Sub
This needs to go in the INPUTS-BULDING DETAILS code module
 
Upvote 0

Forum statistics

Threads
1,214,886
Messages
6,122,093
Members
449,064
Latest member
Danger_SF

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