View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.programming
Bob Kilmer Bob Kilmer is offline
external usenet poster
 
Posts: 280
Default Problem With Select Case

Amen.

--
Bob Kilmer


"Thomas" wrote in message ...
Me thinks its something simple then,check the gas gauge first.

Bob Kilmer wrote:

Thomas,
We questioned Steve on this earlier. I am assuming we are past that. He
reported that MsgBox Left(WkSht.Name, 3) yields what he expects (May,

Jun,
Jul, etc.). He would be getting an error "Object variable or With block
variable not set" if WkSht were Nothing.

--
Bob Kilmer

"Thomas" wrote in message ...
You're gonna have to set wksht somewhere,Where?

Steve wrote:

Thomas,

Rather than Set Wksht, I have For Each Wksht and Next Wksht after

End
Select.

See my last two responses to Bob for what works and what doesn't.

Thanks!

Steve

"Thomas" wrote in message

...
This is basically what you have,does it not run correctly for you
Dim Wksht As Worksheet
Set Wksht = ActiveSheet
Wksht.Activate
MsgBox Left(Wksht.Name, 3)
Select Case Left(Wksht.Name, 3)
Case "May"
MsgBox "My"
Case "Jun"
MsgBox "Jn"
Case "Jul"
MsgBox "Jy"
Case Else
MsgBox " .................."
End Select

Steve wrote:

Bob,

I also tried the following:

If Left(WkSht.Name, 3) = "May" Then
MsgBox "Hello"
End If

and the message "Hello" does not come up.

For a moment I thought it might be a References problem but
Left("Mayville",3)
worked.

Steve

"Bob Kilmer" wrote in message
...
MsgBox "'" & Left(WkSht.Name, 3) & "'" includes a single quote

string at
either end of the Left function, so I would have expected

'May'.
The
single
quotes just bracket the ends of the string, that's all. It's

something I
sometimes do to verify the extents of the string.

I can't imagine why the Select Case is not working for you.

What
do you
get
if you substitute a string for Left()?

Select Case "May"
<<Case Statements
End Select

--
Bob Kilmer

"Steve" wrote in message
hlink.net...
What do you see if you execute MsgBox "'" &

Left(WkSht.Name,
3) & "'"
in
the
Case Else?

"May"

Steve

"Bob Kilmer" wrote in message
...
Dunno, Steve. Worked okay for me. How does Wksht come to

reference a
worksheet? (I don't see a Set statement.)

What do you see if you execute MsgBox "'" &

Left(WkSht.Name,
3) & "'"
in
the
Case Else?

--
Bob Kilmer

"Steve" wrote in message

thlink.net...
I have three worksheets named May-03, Jun-03 and Jul-03

in a
workbook.
I
have
the following code in a macro:

Dim Wksht As Worksheet
Wksht.Activate
MsgBox Left(WkSht.Name, 3)
Select Case Left(WkSht.Name, 3)
Case "May"
RowRef = "467"
Case "Jun"
RowRef = "468"
Case "Jul"
RowRef = "469"
Case Else
MsgBox ..................
End Select

No matter which worksheet I run this on, I get the

correct
name of
the
worksheet
in MsgBox Left(WkSht.Name, 3) but then the Select Case

always go to
the
Case
Else statement. If the Macro gets it right in the Magbox

function,
why
doesn't
it get the Case statement?

Steve