![]() |
select case syntax to other sheets
Excel 2010
Sheet 1 B1 has a drop down with Don, Kim, Bob & " ". What is the proper syntax to get Case Is = "Kim" & Case Is = "Bob" to work properly. Case Is = "Don" works but probably because it is on sheet1. Thanks. Regards, Howard Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) On Error Resume Next Dim TheDon As Range, TheKim As Range, TheBob As Range Set TheDon = Sheets("sheet1").Range("C1:D10") Set TheKim = Sheets("sheet2").Range("E1:F10") Set TheBob = Sheets("sheet3").Range("G1:H10") Select Case ActiveCell.Value Case Is = "Don" TheDon.Select MsgBox "Don's stuff" Case Is = "Kim" TheKim.Select MsgBox "Kim's stuff" Case Is = "Bob" TheBob.Select MsgBox "Bob's stuff" Case Is = " " MsgBox "Blank (space) stuff" End Select End Sub |
select case syntax to other sheets
Your code logic is based on ActiveCell, which is always going to be on
ActiveSheet. If you want to test the value of other cells on other sheets you'll need to activate those sheets respectively, OR use a fully qualified reference to them. In your case a Select Case construct is *not* a good approach. Perhaps if you better explain what it is you're trying to do people here will be better able to offer help! -- Garry Free usenet access at http://www.eternal-september.org ClassicVB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
select case syntax to other sheets
Hi Howard,
Am Thu, 18 Oct 2012 11:49:49 -0700 (PDT) schrieb Howard: Excel 2010 Sheet 1 B1 has a drop down with Don, Kim, Bob & " ". What is the proper syntax to get Case Is = "Kim" & Case Is = "Bob" to work properly. Case Is = "Don" works but probably because it is on sheet1. try: Private Sub Worksheet_Change(ByVal Target As Range) Dim TheDon As Range, TheKim As Range, TheBob As Range If Target.Address < "$B$1" Then Exit Sub ActiveWorkbook.Names.Add Name:="TheDon", _ RefersTo:=Sheets("sheet1").Range("C1:D10") ActiveWorkbook.Names.Add Name:="TheKim", _ RefersTo:=Sheets("sheet2").Range("E1:F10") ActiveWorkbook.Names.Add Name:="TheBob", _ RefersTo:=Sheets("sheet3").Range("G1:H10") Select Case ActiveCell.Value Case Is = "Don" Application.Goto "TheDon" MsgBox "Don's stuff" Case Is = "Kim" Application.Goto "TheKim" MsgBox "Kim's stuff" Case Is = "Bob" Application.Goto "TheBob" MsgBox "Bob's stuff" Case Is = " " MsgBox "Blank (space) stuff" End Select End Sub Regards Claus Busch -- Win XP PRof SP2 / Vista Ultimate SP2 Office 2003 SP2 /2007 Ultimate SP2 |
select case syntax to other sheets
Hi Howard,
Am Thu, 18 Oct 2012 21:12:34 +0200 schrieb Claus Busch: Select Case ActiveCell.Value change to: Select Case Target.Value Regards Claus Busch -- Win XP PRof SP2 / Vista Ultimate SP2 Office 2003 SP2 /2007 Ultimate SP2 |
select case syntax to other sheets
On Thursday, October 18, 2012 11:49:49 AM UTC-7, Howard wrote:
Excel 2010 Sheet 1 B1 has a drop down with Don, Kim, Bob & " ". What is the proper syntax to get Case Is = "Kim" & Case Is = "Bob" to work properly. Case Is = "Don" works but probably because it is on sheet1. Thanks. Regards, Howard Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) On Error Resume Next Dim TheDon As Range, TheKim As Range, TheBob As Range Set TheDon = Sheets("sheet1").Range("C1:D10") Set TheKim = Sheets("sheet2").Range("E1:F10") Set TheBob = Sheets("sheet3").Range("G1:H10") Select Case ActiveCell.Value Case Is = "Don" TheDon.Select MsgBox "Don's stuff" Case Is = "Kim" TheKim.Select MsgBox "Kim's stuff" Case Is = "Bob" TheBob.Select MsgBox "Bob's stuff" Case Is = " " MsgBox "Blank (space) stuff" End Select End Sub Garry and Claus, I began by trying to develop a reply to a post in MISC. However, I got bogged down in this select case attempt. I'm not sure if it will satisfy the poster in MISC but I will pass it on with credit to Claus. It does what I was trying to accomplish. Regards, Howard |
select case syntax to other sheets
On Thursday, October 18, 2012 12:16:03 PM UTC-7, Claus Busch wrote:
Hi Howard, Am Thu, 18 Oct 2012 21:12:34 +0200 schrieb Claus Busch: Select Case ActiveCell.Value change to: Select Case Target.Value Regards Claus Busch -- Win XP PRof SP2 / Vista Ultimate SP2 Office 2003 SP2 /2007 Ultimate SP2 Will do and thanks a ton. I archived your example for future ref. See MISC post titled "Question regarding an auto-search facility" by D4WNO posted today. I passed your code on to that post, and will follow up with the small change you suggested. Regards, Howard |
All times are GMT +1. The time now is 07:01 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com