VBA Conditional Formatting

AdamDN

New Member
Joined
Sep 22, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows
  2. Web
First of all I would share my data but it contains personal information about patients so I will abstain. I will preface through: in my role I receive many reports containing patient data and there is a lot of manual leg work to go and tell where the fallouts are. In this specific spreadsheet we are looking at the times we performed neuro assessments on patients post-stroke. When too much time has elapsed between stroke assessments I am wanting to do guided follow up with individuals to coach to the correct way. What I want is for a whole row to highlight red with red text if more than a given amount of time has elapsed. This will instantly tell me the fallouts and will help identify barriers to care or improve quality of care through associate coaching.

Here is my current macro:

Option Explicit

Sub StrokeSheetFormatting()

Dim lastrow As Long

lastow = shFormatting.Cells(Rows.Count, 3).End.Row

With shFormatting.Range("A14:S21" & lastrow)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula:="=($I15-$I14>(00:30-00:15)"
.FormatConditions(1).Interior.Color = RGB(255, 199, 206)
.FormatConditions(1).Font.Color = RGB(156, 0, 6)
End With

Next

With shFormatting.Range("A24:S33" & lastrow)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula:="=($I15-$I14>(00:45-00:15)"
.FormatConditions(1).Interior.Color = RGB(255, 199, 206)
.FormatConditions(1).Font.Color = RGB(156, 0, 6)
End With

Next

With shFormatting.Range("A36:S49" & lastrow)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula:="=($I15-$I14>(00:30-00:15)"
.FormatConditions(1).Interior.Color = RGB(255, 199, 206)
.FormatConditions(1).Font.Color = RGB(156, 0, 6)
End With



End Sub


The problem I get is it tells me that "shFormatting" is not defined. I am newer to VBA and have done some more basic macros that help with associate scheduling. Otherwise my experience is limited to watching(participating) in so VBA courses from YouTube while fumbling through my scheduling macros before.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
The compiler has no idea what that is. It would have to be either the name of a sheet, or the name of a variable that has been given (assigned) the name of a sheet, or an object variable that is assigned an actual sheet object. Judging by the code, I'm guessing it needs to be a sheet object because you're trying to get at its Range object (With shFormatting.Range). I imagine that if you fix that, you'll still have at least one compile error given that you have
lastrow and lastow, and you seem to be missing a parameter for .End, as in End(xlup)

Much appreciated by all if you'd paste your code within code tags (use vba button on posting toolbar) with proper indentation.
 
Upvote 0

Forum statistics

Threads
1,215,767
Messages
6,126,774
Members
449,336
Latest member
p17tootie

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top