conditional format to last row

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
16,820
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Hi there, I have a very basic conditional format code that I recorded which works fine as far as it goes, but what I would like to do is apply it down to the last used row rather than a range i.e. last used row rather than row 8185 .

Does anyone know the correct syntax for achieving this as I have never attempted conditional formatting with a macro (and probably still wouldn't if the workbook was just for my use)?

Thanks in advance for any suggestions anyone might have.

Current code below

Code:
Range("A2:S8185").Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$S2<$T2"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = True
End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Is there one column that will always have data in it that you can use to determine where the last row is?

Let's say that there is, and it is column "A".

Then we can get the last row like this:

myLastRow=Cells(Rows.Count,"A").End(xlUp).Row

And then we can incorporate that into our range like this:

Range("A2:S" & myLastRow)
 
Upvote 0
Cheers Joe, column A was completely used and all is working well. Thanks a lot for your help.
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,844
Members
452,948
Latest member
UsmanAli786

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