![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Mar 2002
Location: Kevin
Posts: 4
|
Can someone please help out a relative beginner to excel. I would like to make a macro run automatically based on the value of a particular cell on the page. For example, if cell a1=1, then I want my macro named macro1 to run automatically. I am trying to tie this into a date. Can you please help and keep it in simple terms because like I said I am not an expert. Thank you in advance for any help.
|
|
|
|
|
|
#2 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
|
Quote:
What you need to do is this: Right click your worksheet tab and choose View Code. This brings up the code sheet associated with that particular worksheet. You can program Excel to run macros when certain things happen e.g. a cell changing value. If the value in A1 is typed in then you could use this:- Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A" Then
If Target.Value = 1 Then Macro1
End If
End Sub
If the value in A1 is based on a formula which might change because of a non-cell changing entry (e.g. NOW()) then you'd probably be best using the Worksheet_Calculate event:- Code:
Private Sub Worksheet_Calculate()
If Me.Range("A1") = 1 Then Macro1
End Sub
D |
|
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
|
The first procedure should be $A$1.
|
|
|
|
|
|
#4 | |
|
Board Regular
Join Date: Feb 2002
Posts: 95
|
Quote:
Sub macro1() MsgBox ("Hello world") End Sub |
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|