select case syntax to other sheets


H

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.

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
 
Ad

Advertisements

G

GS

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
 
C

Claus Busch

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
 
C

Claus Busch

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
 
H

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.



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
 
Ad

Advertisements

H

Howard

Hi Howard,



Am Thu, 18 Oct 2012 21:12:34 +0200 schrieb Claus Busch:






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
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top