ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how can i use an if statement to run a macro? (https://www.excelbanter.com/excel-programming/324544-how-can-i-use-if-statement-run-macro.html)

jack

how can i use an if statement to run a macro?
 
if ( a1 = 1, run macro, " ")

what code do i need to use to do this?

Jim Thomlinson[_3_]

how can i use an if statement to run a macro?
 
Insert this code into your sheet and you should be good to go.

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" And Target.Value = 1 Then
Call MyMacro 'Insert the name of your macro here
End If
End Sub

To add this to a sheet right click on the sheet tab - select view code
-paste

HTH

"Jack" wrote:

if ( a1 = 1, run macro, " ")

what code do i need to use to do this?


Myrna Larson

how can i use an if statement to run a macro?
 
Are you talkong about a worksheet formula that looks like what you posted? If
so, you can't "run a macro" that carries out actions on the worksheet.

The "macro" can only be a VBA function that returns a value to the cell, just
like SUM or AVERAGE do.


On Thu, 3 Mar 2005 15:29:03 -0800, "Jack"
wrote:

if ( a1 = 1, run macro, " ")

what code do i need to use to do this?




All times are GMT +1. The time now is 08:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com