Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel 2003. Data/Validation/Settings - Allow/List: sizing list? | Excel Discussion (Misc queries) | |||
data validation list: how do i 'force' a user to enter data from the list? | Excel Discussion (Misc queries) | |||
data validation list: how do i 'force' a user to enter data from the list? | Excel Discussion (Misc queries) | |||
data validation invalid in dynamic validation list | Excel Discussion (Misc queries) | |||
data validation invalid in dynamic validation list | Excel Worksheet Functions |