I have a spreadsheet that I put two buttons on. One button runs a macro that conditionally formats dates that will expire in next year and other runs a macro to undo that formating. What I want to do is have just one button - a toggle button that when clicked once shows expirations in red and clicked again will go back the way it was.
I want button to say "Check Experations" to start. Then when clicked makes dates coming in next year red.
The button will then read "Remove Check" So user will click to get rid of the red dates.
I have this as code for first button:
Sub CheckExpireations()
'
' CheckExpireations Macro
'
' Keyboard Shortcut: Ctrl+y
'
Range("D9:AC24").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLessEqual, _
Formula1:="=$AF$1+365"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Color = -16776961
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True
End Sub
And this for code for second button(macro)
Sub Uncheck()
'
' Uncheck Macro
'
' Keyboard Shortcut: Ctrl+r
'
ActiveWindow.ScrollRow = 11
ActiveWindow.ScrollRow = 9
Range("D9:AC24").Select
Selection.FormatConditions.Delete
End Sub
So in short toggle button shows "Check Experations" if Clicked runs macro CheckExperations(). Then button shows "Remove Check" and when clicked runs macro Uncheck()
Thanks for your help
I want button to say "Check Experations" to start. Then when clicked makes dates coming in next year red.
The button will then read "Remove Check" So user will click to get rid of the red dates.
I have this as code for first button:
Sub CheckExpireations()
'
' CheckExpireations Macro
'
' Keyboard Shortcut: Ctrl+y
'
Range("D9:AC24").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLessEqual, _
Formula1:="=$AF$1+365"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Color = -16776961
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True
End Sub
And this for code for second button(macro)
Sub Uncheck()
'
' Uncheck Macro
'
' Keyboard Shortcut: Ctrl+r
'
ActiveWindow.ScrollRow = 11
ActiveWindow.ScrollRow = 9
Range("D9:AC24").Select
Selection.FormatConditions.Delete
End Sub
So in short toggle button shows "Check Experations" if Clicked runs macro CheckExperations(). Then button shows "Remove Check" and when clicked runs macro Uncheck()
Thanks for your help
Last edited: