Macros........work...................automatically

I

Imran Malik

Hello,All
I need help regarding the function that ,e.g, if in cell C5,value is
1,then,automatically runs macro 1,and when value in C5 is 2, then, macro
2,should run automatically,
This is needed for a drop down list, that when i select from that drop
down, or combo box, that macro should work aoutomatically
Thanks and Please if possible reply me at
(e-mail address removed)
Sincerely
imran
 
I

Imran Malik

Ok, i wanna, call a macro when i manually put some value in a cell, so what
should me do, please in easy steps


imran
 
P

Paul B

Imran, see if this will do what you need
To put in this macro right click on the worksheet tab and view code, in the
window that opens paste this code, press Alt and Q to close this window and
go back to your workbook. If you are using excel 2000 or newer you may have
to change the macro security settings to get the macro to run.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Address = "$C$5" And (Target.Value) = 1 Then
macro1
End If
If Target.Address = "$C$5" And (Target.Value) = 2 Then
macro2
End If
End Sub

Then in a normal module to your macros, press alt and F11 to open the VBA
editor, in the left hand window click on your workbook name, go to insert,
module, and paste the code in the window that opens on the right hand side,
press Alt and Q to close this window and go back to your workbook and press
alt and F8, this will bring up a box to pick the Macro from, click on the
Macro name to run it. If you are using excel 2000 or newer you may have to
change the macro security settings to get the macro to run.
Like this
Sub macro1()
MsgBox "this is macro1!"
End Sub
Sub macro2()
MsgBox "this is macro2!"
End Sub


--
Paul B
Always backup your data before trying something new
Using Excel 2000 & 97
Please post any response to the newsgroups so others can benefit from it
** remove news from my email address to reply by email **
 
I

Imran Malik

Thanks to All of you,
That dots and something like that was only to search my question easily,
however i will take care of it .for future
Thanks anyway
 
D

David McRitchie

You're welcome.

Thanks for future consideration eliminating distracting dots through the
subject. Though the important thing is to uniquely describe
your question in a few words so it is known how it is
different from all those questions already answered in the searchable
Google Groups (newsgroups) archives. .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top