Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Macro based on cell value

I have a question similar to one that has been posted before but I tried all
those answers and couldn't get it to work. I have...let's say...12 different
macros, one for each month of the year, that I can assign to buttons and they
work fine. Jan07, Feb07, and so on. On sheet2 in my workbook, Cells F9 and
G9 are merged together and contain a data validation drop down list of those
months. What I would like is that when January-07 is selected, it will run
Jan07, when February-07 is selected it will run Feb07, and so on. One thing
I thought may be affecting it is the fact that when I select a month from the
drop down list, I see it as "January-07" but it seems as though excel has it
as 1/1/2007. Meaning, if I double click the cell to modify it, it would
change from "January-07" to "1/1/2007".

Any help would be greatly appreciated.

Thanks,
Scott
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default Macro based on cell value

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "H1:H10" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Application.Run Format(.Value, "mmmyy")
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"Scott Marcus" wrote in message
...
I have a question similar to one that has been posted before but I tried

all
those answers and couldn't get it to work. I have...let's say...12

different
macros, one for each month of the year, that I can assign to buttons and

they
work fine. Jan07, Feb07, and so on. On sheet2 in my workbook, Cells F9

and
G9 are merged together and contain a data validation drop down list of

those
months. What I would like is that when January-07 is selected, it will

run
Jan07, when February-07 is selected it will run Feb07, and so on. One

thing
I thought may be affecting it is the fact that when I select a month from

the
drop down list, I see it as "January-07" but it seems as though excel has

it
as 1/1/2007. Meaning, if I double click the cell to modify it, it would
change from "January-07" to "1/1/2007".

Any help would be greatly appreciated.

Thanks,
Scott



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Macro based on cell value

Thank you Bob, but I'm not exactly sure what this macro is accomplishing. My
objective is that when cell F9:G9 (they're merged) reads "January-07" this
event macro would call another macro named "Jan07". If the cell reads
"February- 07" it would call macro "Feb07", and so on. I don't know how to
include this into the macro.

Thanks again,
Scott

"Bob Phillips" wrote:

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "H1:H10" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Application.Run Format(.Value, "mmmyy")
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"Scott Marcus" wrote in message
...
I have a question similar to one that has been posted before but I tried

all
those answers and couldn't get it to work. I have...let's say...12

different
macros, one for each month of the year, that I can assign to buttons and

they
work fine. Jan07, Feb07, and so on. On sheet2 in my workbook, Cells F9

and
G9 are merged together and contain a data validation drop down list of

those
months. What I would like is that when January-07 is selected, it will

run
Jan07, when February-07 is selected it will run Feb07, and so on. One

thing
I thought may be affecting it is the fact that when I select a month from

the
drop down list, I see it as "January-07" but it seems as though excel has

it
as 1/1/2007. Meaning, if I double click the cell to modify it, it would
change from "January-07" to "1/1/2007".

Any help would be greatly appreciated.

Thanks,
Scott




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default Macro based on cell value

The macro will trigger when anything is selected from the list, and fires
the corresponding macro.

Change the target range and it should work.

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"Scott Marcus" wrote in message
...
Thank you Bob, but I'm not exactly sure what this macro is accomplishing.

My
objective is that when cell F9:G9 (they're merged) reads "January-07" this
event macro would call another macro named "Jan07". If the cell reads
"February- 07" it would call macro "Feb07", and so on. I don't know how

to
include this into the macro.

Thanks again,
Scott

"Bob Phillips" wrote:

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "H1:H10" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Application.Run Format(.Value, "mmmyy")
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"Scott Marcus" wrote in message
...
I have a question similar to one that has been posted before but I

tried
all
those answers and couldn't get it to work. I have...let's say...12

different
macros, one for each month of the year, that I can assign to buttons

and
they
work fine. Jan07, Feb07, and so on. On sheet2 in my workbook, Cells

F9
and
G9 are merged together and contain a data validation drop down list of

those
months. What I would like is that when January-07 is selected, it

will
run
Jan07, when February-07 is selected it will run Feb07, and so on. One

thing
I thought may be affecting it is the fact that when I select a month

from
the
drop down list, I see it as "January-07" but it seems as though excel

has
it
as 1/1/2007. Meaning, if I double click the cell to modify it, it

would
change from "January-07" to "1/1/2007".

Any help would be greatly appreciated.

Thanks,
Scott






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
Macro based on Cell Value NPell Excel Worksheet Functions 2 June 17th 08 04:50 PM
Run a macro based on a cell value Lisa C. Excel Discussion (Misc queries) 1 March 31st 08 01:11 AM
Run macro based on cell value nowfal[_3_] Excel Programming 2 September 15th 04 10:39 AM
Please help! Macro to change cell contents based on cell to the left Jennifer[_8_] Excel Programming 7 March 4th 04 01:06 AM
Run A Macro based on changes in cell Pete Excel Programming 2 December 2nd 03 03:08 PM


All times are GMT +1. The time now is 04:20 AM.

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

About Us

"It's about Microsoft Excel"