Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run macro based on cell condition


Hello,

How do I run a simple macro, based on a cell condition.

Ex. If A1 is equal to 1, then run a macro that changes a shape from the
drawing tool box, like the cloud to red. If A1 returns to 0, then run
macro to change the cloud color to blue.

Thanks,
EMoe


--
EMoe
------------------------------------------------------------------------
EMoe's Profile: http://www.excelforum.com/member.php...o&userid=23183
View this thread: http://www.excelforum.com/showthread...hreadid=385841

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Run macro based on cell condition

Hi EMoe,

Try:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Me.Shapes(1).Fill.ForeColor
Select Case Range("A1").Value
Case 1: .SchemeColor = 2
Case 0: .SchemeColor = 12
Case Else: .SchemeColor = 11
End Select
End With
End Sub

Amend the numeric in Shapes(1) to the index number or name of the cloud.

This event code needs to br inserted in the sheet module: right-click the
sheet tab | View Code | paste.


---
Regards,
Norman



"EMoe" wrote in message
...

Hello,

How do I run a simple macro, based on a cell condition.

Ex. If A1 is equal to 1, then run a macro that changes a shape from the
drawing tool box, like the cloud to red. If A1 returns to 0, then run
macro to change the cloud color to blue.

Thanks,
EMoe


--
EMoe
------------------------------------------------------------------------
EMoe's Profile:
http://www.excelforum.com/member.php...o&userid=23183
View this thread: http://www.excelforum.com/showthread...hreadid=385841



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Run macro based on cell condition

Hi EMoe,

I intended to use the Change event ( rather than the SelectionChange event):

Private Sub Worksheet_Change(ByVal Target As Range)
With Me.Shapes(1).Fill.ForeColor
Select Case Range("A1").Value
Case 1: .SchemeColor = 2
Case 0: .SchemeColor = 12
Case Else: .SchemeColor = 11
End Select
End With
End Sub

---
Regards,
Norman



"EMoe" wrote in message
...

Hello,

How do I run a simple macro, based on a cell condition.

Ex. If A1 is equal to 1, then run a macro that changes a shape from the
drawing tool box, like the cloud to red. If A1 returns to 0, then run
macro to change the cloud color to blue.

Thanks,
EMoe


--
EMoe
------------------------------------------------------------------------
EMoe's Profile:
http://www.excelforum.com/member.php...o&userid=23183
View this thread: http://www.excelforum.com/showthread...hreadid=385841



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Run macro based on cell condition

And, preferable would be:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.Range("A1")) Is Nothing Then
With Me.Shapes(1).Fill.ForeColor
Select Case Me.Range("A1").Value
Case 1: .SchemeColor = 2
Case 0: .SchemeColor = 12
Case Else: .SchemeColor = 11
End Select
End With
End If
End Sub

---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi EMoe,

I intended to use the Change event ( rather than the SelectionChange
event):

Private Sub Worksheet_Change(ByVal Target As Range)
With Me.Shapes(1).Fill.ForeColor
Select Case Range("A1").Value
Case 1: .SchemeColor = 2
Case 0: .SchemeColor = 12
Case Else: .SchemeColor = 11
End Select
End With
End Sub

---
Regards,
Norman



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run macro based on cell condition


Sorry, but I tried all 3 codes in ''this workbook", as well as in module
1, but the code didn't change the color of the shape.

The name of the cloud is AutoShape 1.

Here's how the code looked in my window:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.Range("A1")) Is Nothing Then
With Me.Shapes(AutoShape1).Fill.ForeColor
Select Case Me.Range("A1").Value
Case 1: .SchemeColor = 2
Case 0: .SchemeColor = 12
Case Else: .SchemeColor = 11
End Select
End With
End If
End Sub

I even tried ("AutoShape 1") in parenthesis, but still no dice.

What did I miss?
EMoe


--
EMoe
------------------------------------------------------------------------
EMoe's Profile: http://www.excelforum.com/member.php...o&userid=23183
View this thread: http://www.excelforum.com/showthread...hreadid=385841



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Run macro based on cell condition

Put it behind the worksheet that contains the shape.

(rightclick on the worksheet tab, select view code and paste it there.)

(Remove it from the ThisWorkbook and the Module1 modules.

EMoe wrote:

Sorry, but I tried all 3 codes in ''this workbook", as well as in module
1, but the code didn't change the color of the shape.

The name of the cloud is AutoShape 1.

Here's how the code looked in my window:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.Range("A1")) Is Nothing Then
With Me.Shapes(AutoShape1).Fill.ForeColor
Select Case Me.Range("A1").Value
Case 1: .SchemeColor = 2
Case 0: .SchemeColor = 12
Case Else: .SchemeColor = 11
End Select
End With
End If
End Sub

I even tried ("AutoShape 1") in parenthesis, but still no dice.

What did I miss?
EMoe

--
EMoe
------------------------------------------------------------------------
EMoe's Profile: http://www.excelforum.com/member.php...o&userid=23183
View this thread: http://www.excelforum.com/showthread...hreadid=385841


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run macro based on cell condition


Works like a charm now.

By the way...

Is there a way, by looking at a code, to know where it goes; in
module, in this workbook, or this worksheet?

Thanks a bunch again for your help.

Regards,
EMo

--
EMo
-----------------------------------------------------------------------
EMoe's Profile: http://www.excelforum.com/member.php...fo&userid=2318
View this thread: http://www.excelforum.com/showthread.php?threadid=38584

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 based on a condition kathryn462 Excel Discussion (Misc queries) 5 October 14th 08 12:59 AM
Macro to delete rows based on a condition Darrilyn Excel Worksheet Functions 1 September 6th 07 12:12 AM
Deactivating a Forms macro button based on a worksheet condition? Ace70 Excel Discussion (Misc queries) 3 June 10th 07 10:31 PM
colore cell based on condition gaba Excel Programming 5 November 2nd 04 08:11 AM
MultiSheet macro, to sum based on condition msMope Excel Programming 1 June 30th 04 08:40 AM


All times are GMT +1. The time now is 04:00 PM.

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

About Us

"It's about Microsoft Excel"