Run a macro

N

nathanuel81

Hey there i was going through my ICT project and wanted to select a
month from a drop down box a macro would run. As at the minute i have a
list of the month is buttons and macros runnning as the buttons are
clicked but i would prefer to having it running as i clicked it from a
drop down box. I have linked the cell I2 so that the number is
displayed as i select it from the dropdown box. So i would like to run
a macro when the number is displayed in theory. I think i would need to
run an =IF command but i dont know what it should be.

Any help would be greatly appreciated

Thanks,
Fanle
 
B

Bob Phillips

You could use event code to trap chnages to I2 and run your code when it
changes

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "I2"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
'do your stuff with the .Value property
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 on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
N

nathanuel81

I'm sorry im new with visul basic commands and dont really understand
what im supposed to but in where you say
With Target
'do your stuff with the .Value property
End With
Thanks
 
B

Bob Phillips

When you select an item, the linked cell holds a value which is stored in
Target.Value when the event procedure rune. This can be tested and your code
act accordingly.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Top