ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Another way to trigger a macro? (https://www.excelbanter.com/excel-programming/348709-another-way-trigger-macro.html)

Leon[_5_]

Another way to trigger a macro?
 
I read previous posts about not being able to trigger a macro through a
function. So my question is: Is there any way to have the macro see
that the IF function is at "true", or false"?

What i am doing is i have an nested if function that says wheather a
person's rent is due today, due soon, is late, or is good. My macro
changes the sheet tab color to red. Now what i need is for the sheet
tab color to be red if the rent is due.

What would be ideal is if it was orange if its due within 30 days and
then bright red if its due or late and white if it is good.

Anyone have any ideas or tips on how i can accomplish this goal?

This is my nested IF function:

"=IF($I$24=TODAY(),"Due",IF($I$24<TODAY(),"Overdue ",IF($I$24<NOW()+30,"Lease
is ending","OK")))"

And my macro right now i just recorded to change the sheet tab to red.

Any tips will be extremely appreciated. Thank you for your time and
help.

Sincerely,
Leon


Norman Jones

Another way to trigger a macro?
 
Hi Leon,

Try something like:

'=============
Private Sub Workbook_Open()
Dim SH As Worksheet
Dim rng As Range

Set SH = Me.Sheets("RENT SHEET") '<<==== CHANGE
Set rng = SH.Range("I24") '<<==== CHANGE

If rng.Value = Date Then
SH.Tab.ColorIndex = 44
ElseIf rng.Value < Date Then
SH.Tab.ColorIndex = 3
Else
SH.Tab.ColorIndex = xlNone
End If

End Sub
'<<=============

This is workbook event code and should be pasted into the workbook's
ThisWorkbook module *not* a standard module or a sheet module):

Right-click the Excel icon on the worksheet
(or the icon to the left of the File menu if your workbook is maximised)
Select 'View Code' from the menu and paste the code.
Alt-F11 to return to Excel.


---
Regards,
Norman


"Leon" wrote in message
oups.com...
I read previous posts about not being able to trigger a macro through a
function. So my question is: Is there any way to have the macro see
that the IF function is at "true", or false"?

What i am doing is i have an nested if function that says wheather a
person's rent is due today, due soon, is late, or is good. My macro
changes the sheet tab color to red. Now what i need is for the sheet
tab color to be red if the rent is due.

What would be ideal is if it was orange if its due within 30 days and
then bright red if its due or late and white if it is good.

Anyone have any ideas or tips on how i can accomplish this goal?

This is my nested IF function:

"=IF($I$24=TODAY(),"Due",IF($I$24<TODAY(),"Overdue ",IF($I$24<NOW()+30,"Lease
is ending","OK")))"

And my macro right now i just recorded to change the sheet tab to red.

Any tips will be extremely appreciated. Thank you for your time and
help.

Sincerely,
Leon





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

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