I have a workbook where sheet 1 is getting inputs from sheet 5 and I want a section of rows on sheet 1 to hide/unhide automatically depending on if something was input on sheet 5. For example, cell D6 on sheet 5 is a name input and when I enter a name (John Smith) that text also populates in cell A5 on sheet 1 with A6:A14 being rows with data concerning John Smith. If sheet 5, cell D6 is blank, I want sheet 1, A5:A14 to automatically hide until I enter a name in D6. And then repeat that same pattern but with different cell references for each section. Like this:
Section 1: Sheet 5 input: D6 Sheet 1: A5 = Sheet5!D6, Rows to hide/unhide: A5:A14
Section 2: Sheet 5 input: F6 Sheet 1: A16 = Sheet5!F6, Rows to hide/unhide: A16:A25
Section 3: Sheet 5 input: H6 Sheet 1: A27 = Sheet5!F6, Rows to hide/unhide: A27:36
And so on for 10 sections and then the pattern changes slightly. But I figure if I can work out how to repeat one pattern, I can then apply the same method to any others.
I found two codes (and modified them a little) on this forum that will work for one section but I can't figure out how to repeat this process for another section (same pattern, different cell references).
1st code:
Option Explicit
Private Sub Worksheet_Activate()
Dim r As Range, c As Range, h As Range
Set r = Range("a5")
Set h = Range("a5:a14")
Application.ScreenUpdating = False
For Each c In r
If Len(c.Text) = 0 Then
h.EntireRow.Hidden = True
Else
h.EntireRow.Hidden = False
End If
Next c
Application.ScreenUpdating = False
End Sub
2nd code
Private Sub Worksheet_Activate()
Dim r As Range
Set r = Range("a5")
If Len(r.Text) = 0 Then
Rows("5:14").EntireRow.Hidden = True
Else
Rows("5:14").EntireRow.Hidden = False
End If
End Sub
I tried adding more ranges like this: Dim r1 As Range, r2 As Range and like this: Dim r(1 To 10) But no luck! I am very new to VBA , so somebody please, please, please tell me what I am doing wrong and how to fix it!
Thank you!!