Selecting the Last Row in multiple columns

Edkins

New Member
Joined
Dec 13, 2018
Messages
2
Hi,

I am using the below formula to select cells for conditional formatting:

Range("A2:A45,F2:F45").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$B2=$F2"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 5287936
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True
Range("A2:A45,F2:F45").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$B2<>$F2"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True

It works from A2 to A45 and F2 to F45 but i need to copy down to the last active row on the sheet. I currently use:
Dim LR As Long
LR = Cells(Rows.Count, 1).End(xlUp).Row

But how do i change Range("A2:A45,F2:F45").Select to use LR?

Thanks
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
One way maybe....

Code:
Dim LR As Long
LR = Cells.Find("*", , xlValues, , xlByRows, xlPrevious).Row
Range("A2:A" & LR & ",F2:F" & LR).Select
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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