98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel Training and help » Invoking Excel Macros
Invoking Excel Macros
Resolved · High Priority · Version 2003
Graham has attended:
Excel Intermediate course
Excel Advanced course
Invoking Excel Macros
I want to run a macro when the value in a cell changes. e.g. if the cell contains the letter "A" macro 1 is run, if it contains the letter "B2 macro 2 is run, and so on. Can this be done?
Many thanks in advance.
Graham
RE: Invoking Excel Macros
Hi Graham
What you require needs a bit of VBA code.
1. Open the Visual Basic Editor
2. Double click the relevant sheet in the Project area.
The code below needs to be pasted into the code area for this sheet.
Dim MySelection As String
Dim Indicator As Boolean
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyValue As String
If Indicator = True Then
MyValue = Range("A1").Value
Select Case MyValue
Case "A"
Call M1
Case "B"
Call M2
Case "C"
Call M3
End Select
Indicator = False
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
MySelection = ActiveCell.Address
If MySelection = "$A$1" Then
Indicator = True
End If
End Sub
Replace the M1, M2 etc with the names of the relevant macros. If more letters are used enter the code immediately after Case "C" following the above pattern.
For a better understanding of the code I suggest you attend our Excel VBA Introduction course.
Hope this helps
Carlos
Tue 17 Mar 2009: Automatically marked as resolved.
Training information:
See also:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Applying and removing border from cell in Excel 2010Did you know the shortcut key for applying and removing the outline border for a cell? |