Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to copy and paste values (columns)I have a macro file built C02C04 Excel Programming 2 May 2nd 08 01:51 PM
AutoRun Macro with a delay to give user the choice to cancel the macro wanderlust Excel Programming 2 September 28th 07 04:09 PM
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort Gavin Excel Worksheet Functions 0 May 17th 07 01:20 PM
macro to delete entire rows when column A is blank ...a quick macro vikram Excel Programming 4 May 3rd 04 08:45 PM
Start Macro / Stop Macro / Restart Macro Pete[_13_] Excel Programming 2 November 21st 03 05:04 PM


All times are GMT +1. The time now is 08:54 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"