invoking excel macros

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel Training and help » Invoking Excel Macros

Invoking Excel Macros

resolvedResolved · 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

Edited on Mon 9 Mar 2009, 14:23

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 courses

 

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
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Applying and removing border from cell in Excel 2010

Did you know the shortcut key for applying and removing the outline border for a cell?

CTRL+SHIFT+& Applies the outline border to the selected cells.
CTRL+SHIFT_ Removes the outline border from the selected cells.

View all Excel hints and tips


Server loaded in 0.1 secs.