LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default assigning macro to cell

Thanks Tom. .. Too much of a hurry!

"Tom Ogilvy" wrote:

Your IF statement says

IF Target.Value = Range("$b$4").Value

so any cell having the same value as Cell B4 (including B4) will execute the
case statement. I doubt that is what your intent is (and it isn't the
stated intent of the OP).

Try

If Target.Address = "$B$4" Then

Instead

--
Regards,
Tom Ogilvy


"Toppers" wrote in message
...
Adam,
Add this code to the sheet which contains the B4 cell . In

VBA
project window, right click on (say) Sheet1, click View Code and copy this
code into the sheet.


Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
If Target = Range("$b$4") Then
With Target
Select Case .Value ' Assumes cell format is General
Case Is = 2005
Call Macro1
Case Is = 2006
Call Macro2
Case Is = 2007
Call Macro3
End Select
End With
End If
ws_exit:
Application.EnableEvents = True
End Sub



HTH

"Adam" wrote:

Is it possible to run a macro depending on the input in a cell?
I would like to run:
Macro 1 if I input 2005 in cell b4
Macro 2 if I input 2006 in cell b4
Macro 3 if I input 2007 in cell b4

Thanks




 
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
assigning value in macro tina Excel Programming 4 October 29th 09 03:33 PM
assigning macro carrera Excel Discussion (Misc queries) 16 March 21st 08 09:00 PM
Assigning A Macro to A Button Holly Excel Worksheet Functions 1 January 18th 08 10:04 AM
Assigning Macro Problem mai[_2_] Excel Programming 4 September 3rd 04 05:24 PM
Macro assigning help PLEASE Jim Rech Excel Programming 0 February 10th 04 10:03 PM


All times are GMT +1. The time now is 08:06 PM.

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"