Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 23
Default Data Validation List Macro

Is there a way to run a macro that hides/unhides multiple worksheets based on
the value selected on a data validation list? If so, what would the VB
syntax be for the macro?

For example, if Cell A1 contains a data validation list with 3 values to
choose from (Account Info, Order Info, Billing Info) and Account Info is
chosen, I want to unhide the Account Info worksheet and hide the Order Info
and Billing Info worksheets. If Order Info is chosen, I want to unhide the
Order Info worksheet, and hide the Account Info and Billing Info worksheets,
etc.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Data Validation List Macro

Sub worksheet_change(ByVal target As Range)

Set isect = Application.Intersect(target, Range("A1"))
If Not isect Is Nothing Then

Select Case Range("A1").Value
Case "Account Info"
Sheets("Account Info").Visible = True
Sheets("Order Info").Visible = False
Sheets("Billing Info").Visible = False

Case "Order Info"
Sheets("Account Info").Visible = False
Sheets("Order Info").Visible = True
Sheets("Billing Info").Visible = False
Case "Billing Info"
Sheets("Account Info").Visible = False
Sheets("Order Info").Visible = False
Sheets("Billing Info").Visible = True
End Select
End If

End Sub



"Lisa C." wrote:

Is there a way to run a macro that hides/unhides multiple worksheets based on
the value selected on a data validation list? If so, what would the VB
syntax be for the macro?

For example, if Cell A1 contains a data validation list with 3 values to
choose from (Account Info, Order Info, Billing Info) and Account Info is
chosen, I want to unhide the Account Info worksheet and hide the Order Info
and Billing Info worksheets. If Order Info is chosen, I want to unhide the
Order Info worksheet, and hide the Account Info and Billing Info worksheets,
etc.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 23
Default Data Validation List Macro

Joel - This worked great. Thank you!

Got another scenario......If I create two different data validation lists on
the same worksheet, one in cell A1 and one in cell A2, is there a way to have
the combination of the two values selected for these cells to run a macro
that hides/unhides worksheets? Do I need to have a third cell (cell X3) with
a formula that concatenates the two values in A1 and A2 and then use cell X3
in the macro? Can you use a target cell in the macro that has a formula in
it but have the macro use the values calculated from it? How do I keep the
macro from kicking off until both cell A1 and A2 have been valued and
combined in cell X3?

"joel" wrote:

Sub worksheet_change(ByVal target As Range)

Set isect = Application.Intersect(target, Range("A1"))
If Not isect Is Nothing Then

Select Case Range("A1").Value
Case "Account Info"
Sheets("Account Info").Visible = True
Sheets("Order Info").Visible = False
Sheets("Billing Info").Visible = False

Case "Order Info"
Sheets("Account Info").Visible = False
Sheets("Order Info").Visible = True
Sheets("Billing Info").Visible = False
Case "Billing Info"
Sheets("Account Info").Visible = False
Sheets("Order Info").Visible = False
Sheets("Billing Info").Visible = True
End Select
End If

End Sub



"Lisa C." wrote:

Is there a way to run a macro that hides/unhides multiple worksheets based on
the value selected on a data validation list? If so, what would the VB
syntax be for the macro?

For example, if Cell A1 contains a data validation list with 3 values to
choose from (Account Info, Order Info, Billing Info) and Account Info is
chosen, I want to unhide the Account Info worksheet and hide the Order Info
and Billing Info worksheets. If Order Info is chosen, I want to unhide the
Order Info worksheet, and hide the Account Info and Billing Info worksheets,
etc.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Data Validation List Macro

Change this one line
from
Set isect = Application.Intersect(target, Range("A1"))
to
Set isect = Application.Intersect(target, Range("A1:A2"))

You need to add additional If statements (or Select Case) to distinquish
between all the different combinations.

You can't stop the macro from running until both values are changed easily.
You would need to use some additional cells to keep a history on the
worksheet would keep the last value of both validation lists. then only make
changes when both are different from the previous value. Then update the
history cells when the 2nd list was changed. I don't think you want to do
this because what happens if you really want to change only one of the cedlls
and not the other.


"Lisa C." wrote:

Joel - This worked great. Thank you!

Got another scenario......If I create two different data validation lists on
the same worksheet, one in cell A1 and one in cell A2, is there a way to have
the combination of the two values selected for these cells to run a macro
that hides/unhides worksheets? Do I need to have a third cell (cell X3) with
a formula that concatenates the two values in A1 and A2 and then use cell X3
in the macro? Can you use a target cell in the macro that has a formula in
it but have the macro use the values calculated from it? How do I keep the
macro from kicking off until both cell A1 and A2 have been valued and
combined in cell X3?

"joel" wrote:

Sub worksheet_change(ByVal target As Range)

Set isect = Application.Intersect(target, Range("A1"))
If Not isect Is Nothing Then

Select Case Range("A1").Value
Case "Account Info"
Sheets("Account Info").Visible = True
Sheets("Order Info").Visible = False
Sheets("Billing Info").Visible = False

Case "Order Info"
Sheets("Account Info").Visible = False
Sheets("Order Info").Visible = True
Sheets("Billing Info").Visible = False
Case "Billing Info"
Sheets("Account Info").Visible = False
Sheets("Order Info").Visible = False
Sheets("Billing Info").Visible = True
End Select
End If

End Sub



"Lisa C." wrote:

Is there a way to run a macro that hides/unhides multiple worksheets based on
the value selected on a data validation list? If so, what would the VB
syntax be for the macro?

For example, if Cell A1 contains a data validation list with 3 values to
choose from (Account Info, Order Info, Billing Info) and Account Info is
chosen, I want to unhide the Account Info worksheet and hide the Order Info
and Billing Info worksheets. If Order Info is chosen, I want to unhide the
Order Info worksheet, and hide the Account Info and Billing Info worksheets,
etc.

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 23
Default Data Validation List Macro

Thank you for replying but I cannot get this to work. For one reason, my
example was wrong. The two cells are not consecutive...they are in cells A1
and A3 but not A2, so I don't want to use A1:A3. Also, I don't like the
macro running when I don't want it to. I think it would it be easier to use
a button macro (named "Continue") that the user selects after he/she has
input values in cells A1 and A3. Then the macro needs to say something like:
If (cell A1) = X and (cell A3 = Y), then hide these sheets and unhide these
sheets. Can you help me with the syntax up until I include the sheets?

"joel" wrote:

Change this one line
from
Set isect = Application.Intersect(target, Range("A1"))
to
Set isect = Application.Intersect(target, Range("A1:A2"))

You need to add additional If statements (or Select Case) to distinquish
between all the different combinations.

You can't stop the macro from running until both values are changed easily.
You would need to use some additional cells to keep a history on the
worksheet would keep the last value of both validation lists. then only make
changes when both are different from the previous value. Then update the
history cells when the 2nd list was changed. I don't think you want to do
this because what happens if you really want to change only one of the cedlls
and not the other.


"Lisa C." wrote:

Joel - This worked great. Thank you!

Got another scenario......If I create two different data validation lists on
the same worksheet, one in cell A1 and one in cell A2, is there a way to have
the combination of the two values selected for these cells to run a macro
that hides/unhides worksheets? Do I need to have a third cell (cell X3) with
a formula that concatenates the two values in A1 and A2 and then use cell X3
in the macro? Can you use a target cell in the macro that has a formula in
it but have the macro use the values calculated from it? How do I keep the
macro from kicking off until both cell A1 and A2 have been valued and
combined in cell X3?

"joel" wrote:

Sub worksheet_change(ByVal target As Range)

Set isect = Application.Intersect(target, Range("A1"))
If Not isect Is Nothing Then

Select Case Range("A1").Value
Case "Account Info"
Sheets("Account Info").Visible = True
Sheets("Order Info").Visible = False
Sheets("Billing Info").Visible = False

Case "Order Info"
Sheets("Account Info").Visible = False
Sheets("Order Info").Visible = True
Sheets("Billing Info").Visible = False
Case "Billing Info"
Sheets("Account Info").Visible = False
Sheets("Order Info").Visible = False
Sheets("Billing Info").Visible = True
End Select
End If

End Sub



"Lisa C." wrote:

Is there a way to run a macro that hides/unhides multiple worksheets based on
the value selected on a data validation list? If so, what would the VB
syntax be for the macro?

For example, if Cell A1 contains a data validation list with 3 values to
choose from (Account Info, Order Info, Billing Info) and Account Info is
chosen, I want to unhide the Account Info worksheet and hide the Order Info
and Billing Info worksheets. If Order Info is chosen, I want to unhide the
Order Info worksheet, and hide the Account Info and Billing Info worksheets,
etc.



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Data Validation List Macro

something like this

Sub HideSheets()

with sheets("Sheet1")
If Not isect Is Nothing Then

Select Case .Range("A1").Value
Case "Account Info"
if .Range("A3") = "abc" then
Sheets("Account Info").Visible = True
Sheets("Order Info").Visible = False
Sheets("Billing Info").Visible = False
end if

Case "Order Info"
if .Range("A3") = "abc" then
Sheets("Account Info").Visible = False
Sheets("Order Info").Visible = True
Sheets("Billing Info").Visible = False
end if

Case "Billing Info"
if .Range("A3") = "abc" then
Sheets("Account Info").Visible = False
Sheets("Order Info").Visible = False
Sheets("Billing Info").Visible = True
end if
End Select
End If
end with
End Sub


"Lisa C." wrote:

Thank you for replying but I cannot get this to work. For one reason, my
example was wrong. The two cells are not consecutive...they are in cells A1
and A3 but not A2, so I don't want to use A1:A3. Also, I don't like the
macro running when I don't want it to. I think it would it be easier to use
a button macro (named "Continue") that the user selects after he/she has
input values in cells A1 and A3. Then the macro needs to say something like:
If (cell A1) = X and (cell A3 = Y), then hide these sheets and unhide these
sheets. Can you help me with the syntax up until I include the sheets?

"joel" wrote:

Change this one line
from
Set isect = Application.Intersect(target, Range("A1"))
to
Set isect = Application.Intersect(target, Range("A1:A2"))

You need to add additional If statements (or Select Case) to distinquish
between all the different combinations.

You can't stop the macro from running until both values are changed easily.
You would need to use some additional cells to keep a history on the
worksheet would keep the last value of both validation lists. then only make
changes when both are different from the previous value. Then update the
history cells when the 2nd list was changed. I don't think you want to do
this because what happens if you really want to change only one of the cedlls
and not the other.


"Lisa C." wrote:

Joel - This worked great. Thank you!

Got another scenario......If I create two different data validation lists on
the same worksheet, one in cell A1 and one in cell A2, is there a way to have
the combination of the two values selected for these cells to run a macro
that hides/unhides worksheets? Do I need to have a third cell (cell X3) with
a formula that concatenates the two values in A1 and A2 and then use cell X3
in the macro? Can you use a target cell in the macro that has a formula in
it but have the macro use the values calculated from it? How do I keep the
macro from kicking off until both cell A1 and A2 have been valued and
combined in cell X3?

"joel" wrote:

Sub worksheet_change(ByVal target As Range)

Set isect = Application.Intersect(target, Range("A1"))
If Not isect Is Nothing Then

Select Case Range("A1").Value
Case "Account Info"
Sheets("Account Info").Visible = True
Sheets("Order Info").Visible = False
Sheets("Billing Info").Visible = False

Case "Order Info"
Sheets("Account Info").Visible = False
Sheets("Order Info").Visible = True
Sheets("Billing Info").Visible = False
Case "Billing Info"
Sheets("Account Info").Visible = False
Sheets("Order Info").Visible = False
Sheets("Billing Info").Visible = True
End Select
End If

End Sub



"Lisa C." wrote:

Is there a way to run a macro that hides/unhides multiple worksheets based on
the value selected on a data validation list? If so, what would the VB
syntax be for the macro?

For example, if Cell A1 contains a data validation list with 3 values to
choose from (Account Info, Order Info, Billing Info) and Account Info is
chosen, I want to unhide the Account Info worksheet and hide the Order Info
and Billing Info worksheets. If Order Info is chosen, I want to unhide the
Order Info worksheet, and hide the Account Info and Billing Info worksheets,
etc.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2003. Data/Validation/Settings - Allow/List: sizing list? Bart Excel Discussion (Misc queries) 1 February 20th 09 01:40 PM
data validation list: how do i 'force' a user to enter data from the list? showsomeidnow Excel Discussion (Misc queries) 4 May 1st 07 05:49 PM
data validation list: how do i 'force' a user to enter data from the list? showsomeidnow Excel Discussion (Misc queries) 2 April 29th 07 11:09 PM
data validation invalid in dynamic validation list ilia Excel Discussion (Misc queries) 0 November 7th 06 12:54 PM
data validation invalid in dynamic validation list ilia Excel Worksheet Functions 0 November 7th 06 12:54 PM


All times are GMT +1. The time now is 03:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"