Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Run macro if
Hi,
I have assigned a macro to an object and I need that object to act as button only when J20=E2. i.e; I should be able to run that macro only if J20=E2. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Run macro if
This goes in the sheet code module for the shee with J20=E2.
Private Sub Worksheet_Change(ByVal Targer As Range) IF Target = Range("J20") Or Target = Range("E2") Then If Range("J20") = Range("E2") Then Call 'myMacro End If End If End Sub When changes are made to either J20 or E2 the procedure will call the macro. You will need to substitute the actual macro name where 'myMacro appears in the code above. "Kashyap" wrote: Hi, I have assigned a macro to an object and I need that object to act as button only when J20=E2. i.e; I should be able to run that macro only if J20=E2. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Run macro if
I do not want macro to be called automatically..
What axactly I need is.. if J20=E2, only then that object should work as button.. "JLGWhiz" wrote: This goes in the sheet code module for the shee with J20=E2. Private Sub Worksheet_Change(ByVal Targer As Range) IF Target = Range("J20") Or Target = Range("E2") Then If Range("J20") = Range("E2") Then Call 'myMacro End If End If End Sub When changes are made to either J20 or E2 the procedure will call the macro. You will need to substitute the actual macro name where 'myMacro appears in the code above. "Kashyap" wrote: Hi, I have assigned a macro to an object and I need that object to act as button only when J20=E2. i.e; I should be able to run that macro only if J20=E2. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Run macro if
In the macro assigned to your object, make this the first line of code:
If NOT Range("J20").Value = Range("E2").Value Then Exit Sub Mike F "Kashyap" wrote in message ... I do not want macro to be called automatically.. What axactly I need is.. if J20=E2, only then that object should work as button.. "JLGWhiz" wrote: This goes in the sheet code module for the shee with J20=E2. Private Sub Worksheet_Change(ByVal Targer As Range) IF Target = Range("J20") Or Target = Range("E2") Then If Range("J20") = Range("E2") Then Call 'myMacro End If End If End Sub When changes are made to either J20 or E2 the procedure will call the macro. You will need to substitute the actual macro name where 'myMacro appears in the code above. "Kashyap" wrote: Hi, I have assigned a macro to an object and I need that object to act as button only when J20=E2. i.e; I should be able to run that macro only if J20=E2. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Run macro if
If you have the macro tied to the object, then you only need to add the If
Then statement which will prevent the macro from running except when the two ranges are equal. If Range("J20") = Range("E2") Then ' <<<your macro code here End If "JLGWhiz" wrote in message ... This goes in the sheet code module for the shee with J20=E2. Private Sub Worksheet_Change(ByVal Targer As Range) IF Target = Range("J20") Or Target = Range("E2") Then If Range("J20") = Range("E2") Then Call 'myMacro End If End If End Sub When changes are made to either J20 or E2 the procedure will call the macro. You will need to substitute the actual macro name where 'myMacro appears in the code above. "Kashyap" wrote: Hi, I have assigned a macro to an object and I need that object to act as button only when J20=E2. i.e; I should be able to run that macro only if J20=E2. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macro to copy and paste values (columns)I have a macro file built | Excel Programming | |||
AutoRun Macro with a delay to give user the choice to cancel the macro | Excel Programming | |||
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort | Excel Worksheet Functions | |||
macro to delete entire rows when column A is blank ...a quick macro | Excel Programming | |||
Start Macro / Stop Macro / Restart Macro | Excel Programming |