我有一个工作簿,其中有多个工作表,其中包括19个数据输入表。如果工作表(E14:E45)
中任何行"IEP"
中的值是"N"
,而unhide
这些行中的值是"Y"
,则我想隐藏相应的数据输入工作表
我已经尝试过Case
和If Else
这两个语句,但是都可以部分工作。
Private Sub worksheet_change(ByVal target As Excel.Range)
Worksheets.IEP.Range ("E14")
Case "N"
If [E14] = "N" Then
Worksheets("ADL-Eat").Visible = False
Else
End If
If [E15] = "N" Then
Worksheets("ADL-Drink").Visible = False
Else
End If
If [E16] = "N" Then
Worksheets("ADL-T").Visible = False
Else
End If
If [E17] = "N" Then
Worksheets("ADL-Dres").Visible = False
Else
End If
If [E18] = "N" Then
Worksheets("CBD").Visible = False
Else
End If
If [E19] = "N" Then
Worksheets("DA").Visible = False
Else
End If
If [E20] = "N" Then
Worksheets("SE-A").Visible = False
Else
End If
If [E21] = "N" Then
Worksheets("SE-GK").Visible = False
Else
End If
If [E22] = "N" Then
Worksheets("Social").Visible = False
Else
End If
If [E23] = "N" Then
Worksheets("SA").Visible = False
Else
End If
If [E24] = "N" Then
End Select
End Sub
Private Sub worksheet_change(ByVal target As Excel.Range)
Worksheets.IEP.Range ("E14")
Case "Y"
If [E14] = "Y" Then
Worksheets("ADL-Eat").Visible = True
Else
End If
If [E15] = "Y" Then
Worksheets("ADL-Drink").Visible = True
Else
End If
If [E16] = "Y" Then
Worksheets("ADL-T").Visible = True
Else
End If
If [E17] = "Y" Then
Worksheets("ADL-Dres").Visible = True
Else
End If
If [E18] = "Y" Then
Worksheets("CBD").Visible = True
Else
End If
If [E19] = "Y" Then
Worksheets("DA").Visible = True
Else
End If
If [E20] = "Y" Then
Worksheets("SE-A").Visible = True
Else
End If
If [E21] = "Y" Then
Worksheets("SE-GK").Visible = True
Else
End If
If [E22] = "Y" Then
Worksheets("Social").Visible = True
Else
End If
If [E23] = "Y" Then
Worksheets("SA").Visible = True
Else
End If
If [E24] = "Y" Then
Worksheets("FS").Visible = True
Else
End If
End Select
End Sub
我希望当行中的值为"N"
时那些表被隐藏,但实际输出是即使值为"N"
时它们也是可见的。
答案 0 :(得分:0)
如果您的工作表如下所示,可以尝试以下代码:
Sub showHideWS()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("IEP") 'Name of the primary worksheet
Dim wsName As String
For a = 14 To 45
wsName = sh.Range("D" & a).Value
If wsName <> "" Then
If sh.Range("E" & a).Value = "N" Then
ThisWorkbook.Sheets(wsName).Visible = False
Else
ThisWorkbook.Sheets(wsName).Visible = True
End If
End If
Next a
End Sub