Hi,
Here’s your explanation form your file…_
_..... sheet "1" is made for cell C4 (ABHISHEK), sheet "2" is made for cell C5 (ANCHAL)…………sheet "65" is made for cell C68 (SHAHNAWAZ HUSAIN)
my requirement is:
If I delete the content of any cell, the corresponding sheet should be hide automatically.
Means, if C4 is blank, sheet 1 hides if C5 is blank, sheet 2 hides….
if I select C6:C9 and delete it, the corresponding sheet should be deleted automatically
Also If I fill the cell again, the corresponding sheet should reappear.
If I paste or delete multiple name in one click, still the corresponding sheets should hide or unhide accordingly….
I am slightly confused that you are talking about hiding and deleting sheets. Hiding and deleting are two very different things
For now I will assume that you are meaning just hiding / unhiding..
If my next shot at a solution is not what you want , then explain carefully again what you want. ( But I will not be able to reply for a couple of days, as I am busy elsewhere )
I will answer this question for now
If I delete the content of any cell, the corresponding sheet should be hide automatically.
Means, if C4 is blank, sheet 1 hides if C5 is blank, sheet 2 hides….
if I select C6:C9 and delete the contents, the corresponding sheets should be hidden automatically
Also If I fill the cell again, the corresponding sheet should reappear.
If I paste or delete multiple names in one click, still the corresponding sheets should hide or unhide accordingly
My previous macro will need to have the initial check for multiple cell selection removed.
I think, a Private Sub Worksheet_Change(ByVal Target As Range) is preferable to a Private Sub Worksheet_SelectionChange(ByVal Target As Range)
The other change is not so substantial. The basic logic remains the same . I simply need to loop for each of the cells changed, and apply the same logic for each of those cells
Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
'Rem 1 Exit sub if more than one cell selectd
' If IsArray(Target.Value) Then Exit Sub
Rem 2 Exit sub if we do not select inside our range of interest
If Application.Intersect(Target, Me.Range("C4:C68")) Is Nothing Then Exit Sub
Rem 3 Do it
Dim WsItmNmbr As Long: ' Let WsItmNmbr = Target.Row - 1
Dim RngCel As Range
For Each RngCel In Target
Let WsItmNmbr = RngCel.Row - 1
'hide unhide worksheet
If RngCel.Value <> "" Then
Worksheets.Item(WsItmNmbr).Visible = True
Else
Worksheets.Item(WsItmNmbr).Visible = False
End If
Next RngCel
End Sub
Alan
Bookmarks