Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Running macros from formula bar

I have a macro that changes the color in certain cells based on the result in
a particular cell. My question is this: can I have it run automatically
based on any new value in that cell or am I forced to run it with a toolbar.
I would prefer that it be done automatically. The basics are these: I have
an excel workbook that contains information about items for sale from
suppliers. One formula computes my minimum profit margin and displays both
the $ amount and the % amount. Another formula computes the maximum
percentage. I have done a macro that changes the backgound color of certain
cells based on the % obtained. Changes cells to red if below 0%. I did a
macro because I could not figure out how to do this with a formula. The
macro is as follows (the commented out portions do not work at present, but
the rest does):

Public Sub ChangeColor()
' Worksheets("Orders").Range("D18").Select
' With Selection
' MAXPPA = "MAXPMA / SMSRP"
If Worksheets("Orders").Range("D18").Value < 0 Then
Worksheets("Orders").Range("C17:C18").Interior.Col orIndex = 3
Else
Worksheets("Orders").Range("C17:C18").Interior.Col orIndex = 0
End If
' End With

End Sub

I would like this to run automatically based on the value in cell D18,
rather than having it run from a button.

Thanks,

/s/ Gene
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Running macros from formula bar

You may be able to tie into some worksheet event (_change, _calculate), but have
you thought of using format|conditional formatting instead.

You can refer to cells in a different worksheet. If you name that range
(insert|name|define) that's used in the format|Conditional formatting dialog.



Gene wrote:

I have a macro that changes the color in certain cells based on the result in
a particular cell. My question is this: can I have it run automatically
based on any new value in that cell or am I forced to run it with a toolbar.
I would prefer that it be done automatically. The basics are these: I have
an excel workbook that contains information about items for sale from
suppliers. One formula computes my minimum profit margin and displays both
the $ amount and the % amount. Another formula computes the maximum
percentage. I have done a macro that changes the backgound color of certain
cells based on the % obtained. Changes cells to red if below 0%. I did a
macro because I could not figure out how to do this with a formula. The
macro is as follows (the commented out portions do not work at present, but
the rest does):

Public Sub ChangeColor()
' Worksheets("Orders").Range("D18").Select
' With Selection
' MAXPPA = "MAXPMA / SMSRP"
If Worksheets("Orders").Range("D18").Value < 0 Then
Worksheets("Orders").Range("C17:C18").Interior.Col orIndex = 3
Else
Worksheets("Orders").Range("C17:C18").Interior.Col orIndex = 0
End If
' End With

End Sub

I would like this to run automatically based on the value in cell D18,
rather than having it run from a button.

Thanks,

/s/ Gene


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Running macros from formula bar

u shd use worksheet event (worksheet_selectionchange)
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
if target=range("d18") then
'put your code here
end if
End Sub

--
Regards,

Sebation.G


"Gene" ...
I have a macro that changes the color in certain cells based on the result
in
a particular cell. My question is this: can I have it run automatically
based on any new value in that cell or am I forced to run it with a
toolbar.
I would prefer that it be done automatically. The basics are these: I
have
an excel workbook that contains information about items for sale from
suppliers. One formula computes my minimum profit margin and displays
both
the $ amount and the % amount. Another formula computes the maximum
percentage. I have done a macro that changes the backgound color of
certain
cells based on the % obtained. Changes cells to red if below 0%. I did a
macro because I could not figure out how to do this with a formula. The
macro is as follows (the commented out portions do not work at present,
but
the rest does):

Public Sub ChangeColor()
' Worksheets("Orders").Range("D18").Select
' With Selection
' MAXPPA = "MAXPMA / SMSRP"
If Worksheets("Orders").Range("D18").Value < 0 Then
Worksheets("Orders").Range("C17:C18").Interior.Col orIndex = 3
Else
Worksheets("Orders").Range("C17:C18").Interior.Col orIndex = 0
End If
' End With

End Sub

I would like this to run automatically based on the value in cell D18,
rather than having it run from a button.

Thanks,

/s/ Gene



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Running macros from formula bar

Thank you Dave. I did not realize it was so easy

"Dave Peterson" wrote:

You may be able to tie into some worksheet event (_change, _calculate), but have
you thought of using format|conditional formatting instead.

You can refer to cells in a different worksheet. If you name that range
(insert|name|define) that's used in the format|Conditional formatting dialog.



Gene wrote:

I have a macro that changes the color in certain cells based on the result in
a particular cell. My question is this: can I have it run automatically
based on any new value in that cell or am I forced to run it with a toolbar.
I would prefer that it be done automatically. The basics are these: I have
an excel workbook that contains information about items for sale from
suppliers. One formula computes my minimum profit margin and displays both
the $ amount and the % amount. Another formula computes the maximum
percentage. I have done a macro that changes the backgound color of certain
cells based on the % obtained. Changes cells to red if below 0%. I did a
macro because I could not figure out how to do this with a formula. The
macro is as follows (the commented out portions do not work at present, but
the rest does):

Public Sub ChangeColor()
' Worksheets("Orders").Range("D18").Select
' With Selection
' MAXPPA = "MAXPMA / SMSRP"
If Worksheets("Orders").Range("D18").Value < 0 Then
Worksheets("Orders").Range("C17:C18").Interior.Col orIndex = 3
Else
Worksheets("Orders").Range("C17:C18").Interior.Col orIndex = 0
End If
' End With

End Sub

I would like this to run automatically based on the value in cell D18,
rather than having it run from a button.

Thanks,

/s/ Gene


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Running macros from formula bar

Thank you Sebation. I will play with your suggestion later. The other
method got what I wanted in the near term. I am better at vbscript than excel
programming.
/s/ Gene

"Sebation.G" wrote:

u shd use worksheet event (worksheet_selectionchange)
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
if target=range("d18") then
'put your code here
end if
End Sub

--
Regards,

Sebation.G


"Gene" ...
I have a macro that changes the color in certain cells based on the result
in
a particular cell. My question is this: can I have it run automatically
based on any new value in that cell or am I forced to run it with a
toolbar.
I would prefer that it be done automatically. The basics are these: I
have
an excel workbook that contains information about items for sale from
suppliers. One formula computes my minimum profit margin and displays
both
the $ amount and the % amount. Another formula computes the maximum
percentage. I have done a macro that changes the backgound color of
certain
cells based on the % obtained. Changes cells to red if below 0%. I did a
macro because I could not figure out how to do this with a formula. The
macro is as follows (the commented out portions do not work at present,
but
the rest does):

Public Sub ChangeColor()
' Worksheets("Orders").Range("D18").Select
' With Selection
' MAXPPA = "MAXPMA / SMSRP"
If Worksheets("Orders").Range("D18").Value < 0 Then
Worksheets("Orders").Range("C17:C18").Interior.Col orIndex = 3
Else
Worksheets("Orders").Range("C17:C18").Interior.Col orIndex = 0
End If
' End With

End Sub

I would like this to run automatically based on the value in cell D18,
rather than having it run from a button.

Thanks,

/s/ Gene




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
Running Macros Excel Discussion (Misc queries) 1 July 6th 06 04:21 PM
HELP - Running Macros in VBA Louise New Users to Excel 7 April 6th 05 03:21 PM
Running Macros simpleS Setting up and Configuration of Excel 1 February 17th 05 02:32 PM
Running Macros Steve Excel Programming 5 September 21st 04 02:54 PM
HELP: Running two Macros, one before the other Bobbak Excel Programming 3 December 8th 03 02:08 PM


All times are GMT +1. The time now is 01:28 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"