Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Using "case" code in Excel

I have the following problem. Cell J2 contains a drop-down menu of week
days. I am trying to use VBA to check the text in cell J2, and then run a
macro that matches the week day. The code follows, but it doesn't seem to
work. Any suggestions?

Sub selectthecase()

Dim r As Range
Set r = Range("J2")

Select Case r
Case Is = "MONDAY"
Call MondayMacro
Case Is = "TUESDAY"
Call TuesdayMacro
Case Is = "WEDNESDAY"
Call WednesdayMacro
Case Is = "THURSDAY"
Call ThursdayMacro
Case Is = "FRIDAY"
Call FridayMacro
Case Is = "SATURDAY"
Call SaturdayMacro
End Select

End Sub
--
Howard
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Using "case" code in Excel

Do you really have MONDAY in J2? All upper case???

If it's not all upper case, ...

select case lcase(r.value)
case is = lcase("monday")
call MondayMacro
case is = lcase("tuesday")
....



Howard wrote:

I have the following problem. Cell J2 contains a drop-down menu of week
days. I am trying to use VBA to check the text in cell J2, and then run a
macro that matches the week day. The code follows, but it doesn't seem to
work. Any suggestions?

Sub selectthecase()

Dim r As Range
Set r = Range("J2")

Select Case r
Case Is = "MONDAY"
Call MondayMacro
Case Is = "TUESDAY"
Call TuesdayMacro
Case Is = "WEDNESDAY"
Call WednesdayMacro
Case Is = "THURSDAY"
Call ThursdayMacro
Case Is = "FRIDAY"
Call FridayMacro
Case Is = "SATURDAY"
Call SaturdayMacro
End Select

End Sub
--
Howard


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Using "case" code in Excel

Dave:
Yes, Monday is all uppercase. I use a drop-down menu so that the user has
to enter the correct spelling. When I manually run the sub, it works, but I
think that what I need is script that makes the sub run when ever the text in
J2 is changed. Any ideas?
Thanks
--
Howard


"Dave Peterson" wrote:

Do you really have MONDAY in J2? All upper case???

If it's not all upper case, ...

select case lcase(r.value)
case is = lcase("monday")
call MondayMacro
case is = lcase("tuesday")
....



Howard wrote:

I have the following problem. Cell J2 contains a drop-down menu of week
days. I am trying to use VBA to check the text in cell J2, and then run a
macro that matches the week day. The code follows, but it doesn't seem to
work. Any suggestions?

Sub selectthecase()

Dim r As Range
Set r = Range("J2")

Select Case r
Case Is = "MONDAY"
Call MondayMacro
Case Is = "TUESDAY"
Call TuesdayMacro
Case Is = "WEDNESDAY"
Call WednesdayMacro
Case Is = "THURSDAY"
Call ThursdayMacro
Case Is = "FRIDAY"
Call FridayMacro
Case Is = "SATURDAY"
Call SaturdayMacro
End Select

End Sub
--
Howard


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Using "case" code in Excel

Try this:

Private Sub Worksheet_Change(ByVal Target As Range)

If Target = Range("J2") Then
Dim r As Range
Set r = Range("J2")

Select Case r
Case Is = "MONDAY"
Call MondayMacro
Case Is = "TUESDAY"
Call TuesdayMacro
Case Is = "WEDNESDAY"
Call WednesdayMacro
Case Is = "THURSDAY"
Call ThursdayMacro
Case Is = "FRIDAY"
Call FridayMacro
Case Is = "SATURDAY"
Call SaturdayMacro
End Select

End If
End Sub







"Howard" wrote:

Dave:
Yes, Monday is all uppercase. I use a drop-down menu so that the user has
to enter the correct spelling. When I manually run the sub, it works, but I
think that what I need is script that makes the sub run when ever the text in
J2 is changed. Any ideas?
Thanks
--
Howard


"Dave Peterson" wrote:

Do you really have MONDAY in J2? All upper case???

If it's not all upper case, ...

select case lcase(r.value)
case is = lcase("monday")
call MondayMacro
case is = lcase("tuesday")
....



Howard wrote:

I have the following problem. Cell J2 contains a drop-down menu of week
days. I am trying to use VBA to check the text in cell J2, and then run a
macro that matches the week day. The code follows, but it doesn't seem to
work. Any suggestions?

Sub selectthecase()

Dim r As Range
Set r = Range("J2")

Select Case r
Case Is = "MONDAY"
Call MondayMacro
Case Is = "TUESDAY"
Call TuesdayMacro
Case Is = "WEDNESDAY"
Call WednesdayMacro
Case Is = "THURSDAY"
Call ThursdayMacro
Case Is = "FRIDAY"
Call FridayMacro
Case Is = "SATURDAY"
Call SaturdayMacro
End Select

End Sub
--
Howard


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Using "case" code in Excel

Not sure what I'm doing wrong. It still doesn't work. Maybe I'm explaining
it wrong. When I go to the worksheet and change cell J2 from one day (say
Monday) to another, (say Tuesday), I want the sub to run and run the macro
associated with either Monday or Tuesday, etc.
PS--I really appreciate the help from you people. Thanks
--
Howard


"JLGWhiz" wrote:

Try this:

Private Sub Worksheet_Change(ByVal Target As Range)

If Target = Range("J2") Then
Dim r As Range
Set r = Range("J2")

Select Case r
Case Is = "MONDAY"
Call MondayMacro
Case Is = "TUESDAY"
Call TuesdayMacro
Case Is = "WEDNESDAY"
Call WednesdayMacro
Case Is = "THURSDAY"
Call ThursdayMacro
Case Is = "FRIDAY"
Call FridayMacro
Case Is = "SATURDAY"
Call SaturdayMacro
End Select

End If
End Sub







"Howard" wrote:

Dave:
Yes, Monday is all uppercase. I use a drop-down menu so that the user has
to enter the correct spelling. When I manually run the sub, it works, but I
think that what I need is script that makes the sub run when ever the text in
J2 is changed. Any ideas?
Thanks
--
Howard


"Dave Peterson" wrote:

Do you really have MONDAY in J2? All upper case???

If it's not all upper case, ...

select case lcase(r.value)
case is = lcase("monday")
call MondayMacro
case is = lcase("tuesday")
....



Howard wrote:

I have the following problem. Cell J2 contains a drop-down menu of week
days. I am trying to use VBA to check the text in cell J2, and then run a
macro that matches the week day. The code follows, but it doesn't seem to
work. Any suggestions?

Sub selectthecase()

Dim r As Range
Set r = Range("J2")

Select Case r
Case Is = "MONDAY"
Call MondayMacro
Case Is = "TUESDAY"
Call TuesdayMacro
Case Is = "WEDNESDAY"
Call WednesdayMacro
Case Is = "THURSDAY"
Call ThursdayMacro
Case Is = "FRIDAY"
Call FridayMacro
Case Is = "SATURDAY"
Call SaturdayMacro
End Select

End Sub
--
Howard

--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Using "case" code in Excel

You need to put the code I gave you in the worksheet code module. Right
click the sheet tab for the sheet you have the dropdown box on and select
"View Code". When the VBE window opens, paste the code into that window.
Then try it. If it works, save the file.

Worksheet_change event code has to be in the code module for the sheet it
applies to. It will not work from the standard Module1.

"Howard" wrote:

Not sure what I'm doing wrong. It still doesn't work. Maybe I'm explaining
it wrong. When I go to the worksheet and change cell J2 from one day (say
Monday) to another, (say Tuesday), I want the sub to run and run the macro
associated with either Monday or Tuesday, etc.
PS--I really appreciate the help from you people. Thanks
--
Howard


"JLGWhiz" wrote:

Try this:

Private Sub Worksheet_Change(ByVal Target As Range)

If Target = Range("J2") Then
Dim r As Range
Set r = Range("J2")

Select Case r
Case Is = "MONDAY"
Call MondayMacro
Case Is = "TUESDAY"
Call TuesdayMacro
Case Is = "WEDNESDAY"
Call WednesdayMacro
Case Is = "THURSDAY"
Call ThursdayMacro
Case Is = "FRIDAY"
Call FridayMacro
Case Is = "SATURDAY"
Call SaturdayMacro
End Select

End If
End Sub







"Howard" wrote:

Dave:
Yes, Monday is all uppercase. I use a drop-down menu so that the user has
to enter the correct spelling. When I manually run the sub, it works, but I
think that what I need is script that makes the sub run when ever the text in
J2 is changed. Any ideas?
Thanks
--
Howard


"Dave Peterson" wrote:

Do you really have MONDAY in J2? All upper case???

If it's not all upper case, ...

select case lcase(r.value)
case is = lcase("monday")
call MondayMacro
case is = lcase("tuesday")
....



Howard wrote:

I have the following problem. Cell J2 contains a drop-down menu of week
days. I am trying to use VBA to check the text in cell J2, and then run a
macro that matches the week day. The code follows, but it doesn't seem to
work. Any suggestions?

Sub selectthecase()

Dim r As Range
Set r = Range("J2")

Select Case r
Case Is = "MONDAY"
Call MondayMacro
Case Is = "TUESDAY"
Call TuesdayMacro
Case Is = "WEDNESDAY"
Call WednesdayMacro
Case Is = "THURSDAY"
Call ThursdayMacro
Case Is = "FRIDAY"
Call FridayMacro
Case Is = "SATURDAY"
Call SaturdayMacro
End Select

End Sub
--
Howard

--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Using "case" code in Excel

I tried that and I get an error message that says:
Compile error:
Ambiguous name detected: Worksheet_change


--
Howard


"JLGWhiz" wrote:

You need to put the code I gave you in the worksheet code module. Right
click the sheet tab for the sheet you have the dropdown box on and select
"View Code". When the VBE window opens, paste the code into that window.
Then try it. If it works, save the file.

Worksheet_change event code has to be in the code module for the sheet it
applies to. It will not work from the standard Module1.

"Howard" wrote:

Not sure what I'm doing wrong. It still doesn't work. Maybe I'm explaining
it wrong. When I go to the worksheet and change cell J2 from one day (say
Monday) to another, (say Tuesday), I want the sub to run and run the macro
associated with either Monday or Tuesday, etc.
PS--I really appreciate the help from you people. Thanks
--
Howard


"JLGWhiz" wrote:

Try this:

Private Sub Worksheet_Change(ByVal Target As Range)

If Target = Range("J2") Then
Dim r As Range
Set r = Range("J2")

Select Case r
Case Is = "MONDAY"
Call MondayMacro
Case Is = "TUESDAY"
Call TuesdayMacro
Case Is = "WEDNESDAY"
Call WednesdayMacro
Case Is = "THURSDAY"
Call ThursdayMacro
Case Is = "FRIDAY"
Call FridayMacro
Case Is = "SATURDAY"
Call SaturdayMacro
End Select

End If
End Sub







"Howard" wrote:

Dave:
Yes, Monday is all uppercase. I use a drop-down menu so that the user has
to enter the correct spelling. When I manually run the sub, it works, but I
think that what I need is script that makes the sub run when ever the text in
J2 is changed. Any ideas?
Thanks
--
Howard


"Dave Peterson" wrote:

Do you really have MONDAY in J2? All upper case???

If it's not all upper case, ...

select case lcase(r.value)
case is = lcase("monday")
call MondayMacro
case is = lcase("tuesday")
....



Howard wrote:

I have the following problem. Cell J2 contains a drop-down menu of week
days. I am trying to use VBA to check the text in cell J2, and then run a
macro that matches the week day. The code follows, but it doesn't seem to
work. Any suggestions?

Sub selectthecase()

Dim r As Range
Set r = Range("J2")

Select Case r
Case Is = "MONDAY"
Call MondayMacro
Case Is = "TUESDAY"
Call TuesdayMacro
Case Is = "WEDNESDAY"
Call WednesdayMacro
Case Is = "THURSDAY"
Call ThursdayMacro
Case Is = "FRIDAY"
Call FridayMacro
Case Is = "SATURDAY"
Call SaturdayMacro
End Select

End Sub
--
Howard

--

Dave Peterson

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Using "case" code in Excel

You have to delete the old code in the stadard module1.

You can't have a code in the standard module with the same name. It
confuses the compiler.

You also cannot have two worksheet_change event codes in the same sheet
module.

You can, however, combine two event procedures under one change event title.

I am going to bed now. If you have more proplems, start a new thread and
maybe someone else will pick it up.

"Howard" wrote:

I tried that and I get an error message that says:
Compile error:
Ambiguous name detected: Worksheet_change


--
Howard


"JLGWhiz" wrote:

You need to put the code I gave you in the worksheet code module. Right
click the sheet tab for the sheet you have the dropdown box on and select
"View Code". When the VBE window opens, paste the code into that window.
Then try it. If it works, save the file.

Worksheet_change event code has to be in the code module for the sheet it
applies to. It will not work from the standard Module1.

"Howard" wrote:

Not sure what I'm doing wrong. It still doesn't work. Maybe I'm explaining
it wrong. When I go to the worksheet and change cell J2 from one day (say
Monday) to another, (say Tuesday), I want the sub to run and run the macro
associated with either Monday or Tuesday, etc.
PS--I really appreciate the help from you people. Thanks
--
Howard


"JLGWhiz" wrote:

Try this:

Private Sub Worksheet_Change(ByVal Target As Range)

If Target = Range("J2") Then
Dim r As Range
Set r = Range("J2")

Select Case r
Case Is = "MONDAY"
Call MondayMacro
Case Is = "TUESDAY"
Call TuesdayMacro
Case Is = "WEDNESDAY"
Call WednesdayMacro
Case Is = "THURSDAY"
Call ThursdayMacro
Case Is = "FRIDAY"
Call FridayMacro
Case Is = "SATURDAY"
Call SaturdayMacro
End Select

End If
End Sub







"Howard" wrote:

Dave:
Yes, Monday is all uppercase. I use a drop-down menu so that the user has
to enter the correct spelling. When I manually run the sub, it works, but I
think that what I need is script that makes the sub run when ever the text in
J2 is changed. Any ideas?
Thanks
--
Howard


"Dave Peterson" wrote:

Do you really have MONDAY in J2? All upper case???

If it's not all upper case, ...

select case lcase(r.value)
case is = lcase("monday")
call MondayMacro
case is = lcase("tuesday")
....



Howard wrote:

I have the following problem. Cell J2 contains a drop-down menu of week
days. I am trying to use VBA to check the text in cell J2, and then run a
macro that matches the week day. The code follows, but it doesn't seem to
work. Any suggestions?

Sub selectthecase()

Dim r As Range
Set r = Range("J2")

Select Case r
Case Is = "MONDAY"
Call MondayMacro
Case Is = "TUESDAY"
Call TuesdayMacro
Case Is = "WEDNESDAY"
Call WednesdayMacro
Case Is = "THURSDAY"
Call ThursdayMacro
Case Is = "FRIDAY"
Call FridayMacro
Case Is = "SATURDAY"
Call SaturdayMacro
End Select

End Sub
--
Howard

--

Dave Peterson

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Using "case" code in Excel

Thanks for all your help, and have a good eveing.
--
Howard


"JLGWhiz" wrote:

You have to delete the old code in the stadard module1.

You can't have a code in the standard module with the same name. It
confuses the compiler.

You also cannot have two worksheet_change event codes in the same sheet
module.

You can, however, combine two event procedures under one change event title.

I am going to bed now. If you have more proplems, start a new thread and
maybe someone else will pick it up.

"Howard" wrote:

I tried that and I get an error message that says:
Compile error:
Ambiguous name detected: Worksheet_change


--
Howard


"JLGWhiz" wrote:

You need to put the code I gave you in the worksheet code module. Right
click the sheet tab for the sheet you have the dropdown box on and select
"View Code". When the VBE window opens, paste the code into that window.
Then try it. If it works, save the file.

Worksheet_change event code has to be in the code module for the sheet it
applies to. It will not work from the standard Module1.

"Howard" wrote:

Not sure what I'm doing wrong. It still doesn't work. Maybe I'm explaining
it wrong. When I go to the worksheet and change cell J2 from one day (say
Monday) to another, (say Tuesday), I want the sub to run and run the macro
associated with either Monday or Tuesday, etc.
PS--I really appreciate the help from you people. Thanks
--
Howard


"JLGWhiz" wrote:

Try this:

Private Sub Worksheet_Change(ByVal Target As Range)

If Target = Range("J2") Then
Dim r As Range
Set r = Range("J2")

Select Case r
Case Is = "MONDAY"
Call MondayMacro
Case Is = "TUESDAY"
Call TuesdayMacro
Case Is = "WEDNESDAY"
Call WednesdayMacro
Case Is = "THURSDAY"
Call ThursdayMacro
Case Is = "FRIDAY"
Call FridayMacro
Case Is = "SATURDAY"
Call SaturdayMacro
End Select

End If
End Sub







"Howard" wrote:

Dave:
Yes, Monday is all uppercase. I use a drop-down menu so that the user has
to enter the correct spelling. When I manually run the sub, it works, but I
think that what I need is script that makes the sub run when ever the text in
J2 is changed. Any ideas?
Thanks
--
Howard


"Dave Peterson" wrote:

Do you really have MONDAY in J2? All upper case???

If it's not all upper case, ...

select case lcase(r.value)
case is = lcase("monday")
call MondayMacro
case is = lcase("tuesday")
....



Howard wrote:

I have the following problem. Cell J2 contains a drop-down menu of week
days. I am trying to use VBA to check the text in cell J2, and then run a
macro that matches the week day. The code follows, but it doesn't seem to
work. Any suggestions?

Sub selectthecase()

Dim r As Range
Set r = Range("J2")

Select Case r
Case Is = "MONDAY"
Call MondayMacro
Case Is = "TUESDAY"
Call TuesdayMacro
Case Is = "WEDNESDAY"
Call WednesdayMacro
Case Is = "THURSDAY"
Call ThursdayMacro
Case Is = "FRIDAY"
Call FridayMacro
Case Is = "SATURDAY"
Call SaturdayMacro
End Select

End Sub
--
Howard

--

Dave Peterson

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Using "case" code in Excel

Just a slightly different idea...
If there really is no Sunday, then just have a Sunday Macro that does
nothing.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address < Range("J2").Address Then Exit Sub

Dim WD As String 'WeekDay
Dim Valid As Boolean

WD = Target.Value
On Error Resume Next
Valid = WorksheetFunction.Match(WD, _
Application.GetCustomListContents(2), 0) 0
If Valid Then Run WD & "Macro"
End Sub

= = =
HTH
Dana DeLouis


Howard wrote:
Thanks for all your help, and have a good eveing.

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
lower case letter "i" always converts to upper case Carolyn Excel Discussion (Misc queries) 1 August 28th 08 01:56 AM
Converting "uppercase" string data to "lower case" in CSV file [email protected] Excel Discussion (Misc queries) 2 August 12th 08 08:36 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
how do I count only lower case "x" and exclude upper case "X" jbeletz Excel Worksheet Functions 3 October 14th 06 10:50 PM
Fix Code: Select Case and "Contains" selection Bettergains Excel Programming 5 April 26th 05 02:22 AM


All times are GMT +1. The time now is 04:19 PM.

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

About Us

"It's about Microsoft Excel"