Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2007

Tip: Looking for answers? Try searching our database.

Worksheet change to control worksheet visibility

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AVR - 26 Jan 2007 21:41 GMT
I am working in a sheet with 2 different data validation cells, named as
ranges "DV1" and "DV2" respectively.  The only values for the cells are "Yes"
or "No".  When one of those 2 cells changes, I want to hide or unhide other
sheets, based on the value in the changed cell.  The following code is
running, but the visibility of the sheets is unaffected.  What am I doing
wrong?

'Private Sub Worksheet_Change(ByVal Target As Range)
'
'    a = Target.Address
'    b = Target.Value
'    x = Range("DV1").Address
'    y = Range("DV2").Address
'
'    If a = x Then
'
'        If b = "Yes" Then
'            Sheets("ShDV1A").Visible = True
'            Sheets("ShDV1B").Visible = True
'        Else
'            Sheets("ShDV1A").Visible = False
'            Sheets("ShDV1B").Visible = False
'        End If
'
'    ElseIf a = y Then
'
'        If b = "Yes" Then
'            Sheets("ShDV2A").Visible = True
'            Sheets("ShDV2B").Visible = True
'        Else
'            Sheets("ShDV2A").Visible = False
'            Sheets("ShDV2B").Visible = False
'        End If
'
'    End If
'
'
'End Sub
Corey - 26 Jan 2007 22:22 GMT
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("A1").Value = "yes" Then
Sheets("Sheet2").Visible = False
   Else
    Sheets("Sheet2").Visible = True
   End If

End Sub

Change to suit

Corey....

>I am working in a sheet with 2 different data validation cells, named as
> ranges "DV1" and "DV2" respectively.  The only values for the cells are
[quoted text clipped - 36 lines]
> '
> 'End Sub
AVR - 26 Jan 2007 22:30 GMT
Thanks for the post.  Do you know why my code didn't work?

> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> If Range("A1").Value = "yes" Then
[quoted text clipped - 49 lines]
> > '
> > 'End Sub
Jim Cone - 26 Jan 2007 22:28 GMT
If I interpret your message correctly, you have assigned names to 2 cells
using names that are identical to a valid cell address.
Excel could be confused trying to determine if Range("DV1") refers to
the named range or to that actual cell.
Signature

Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware

"AVR" <AVR@discussions.microsoft.com>
wrote in message
I am working in a sheet with 2 different data validation cells, named as
ranges "DV1" and "DV2" respectively.  The only values for the cells are "Yes"
or "No".  When one of those 2 cells changes, I want to hide or unhide other
sheets, based on the value in the changed cell.  The following code is
running, but the visibility of the sheets is unaffected.  What am I doing
wrong?

'Private Sub Worksheet_Change(ByVal Target As Range)
'    a = Target.Address
'    b = Target.Value
'    x = Range("DV1").Address
'    y = Range("DV2").Address
'
'    If a = x Then'
'        If b = "Yes" Then
'            Sheets("ShDV1A").Visible = True
'            Sheets("ShDV1B").Visible = True
'        Else
'            Sheets("ShDV1A").Visible = False
'            Sheets("ShDV1B").Visible = False
'        End If
'
'    ElseIf a = y Then'
'        If b = "Yes" Then
'            Sheets("ShDV2A").Visible = True
'            Sheets("ShDV2B").Visible = True
'        Else
'            Sheets("ShDV2A").Visible = False
'            Sheets("ShDV2B").Visible = False
'        End If
'
'    End If'
'End Sub

AVR - 27 Jan 2007 00:27 GMT
The actual range names I used are not valid cell addresses...just text.  In
order to shorten the code for the post, I cut the names down and accidentally
created valid cell addresses.  To avoid confusion,  replace DV1 and DV2 with
DataVal1 and DataVal2.  My question still stands.  What is wrong with my
code?  What I want the procedure to do is identify whether the change event
was triggered by one of the 2 named cells, and if so, which one...then make
the appropriate changes to the workbook by hiding / unhiding other sheets.  
There are many other cells in the sheet which may change, but those events
should be ignored by the procedure.

Thanks for your help.

> If I interpret your message correctly, you have assigned names to 2 cells
> using names that are identical to a valid cell address.
> Excel could be confused trying to determine if Range("DV1") refers to
> the named range or to that actual cell.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.