last used cell in range xlup

BRB1983

Board Regular
Joined
Aug 29, 2019
Messages
61
how can i shorten up a range with usedrange in a range? or how to properly use last row used xlup? something like:
set source = range ("E3:E4000").usedrange or set source = range ("E3").end.xlup

Code:
Set source = Range("E3:E4000")    
      source.Interior.Color = xlNone
For Each cell In source
    If Application.WorksheetFunction.CountIf(source, cell) > 1 Then
        cell.Interior.Color = RGB(255, 0, 0)
        cell.Offset(0, -1).Interior.Color = RGB(255, 0, 0)
        cell.Offset(0, -2).Interior.Color = RGB(255, 0, 0)
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
How about
Code:
Set source = Range("E3", Range("E" & Rows.Count).End(xlUp))
 
Upvote 0
Another way:

Code:
Set source = Range("E3:E" & Range("E" & Rows.Count).End(xlUp).Row)


Or separately to understand how to get the last line.

Code:
  Dim source As Range, lr As Long
  lr = Range("E" & Rows.Count).End(xlUp).Row
  Set source = Range("E3:E" & lr)
 
Upvote 0
You're welcome & thanks for the feedback.

Not sure if you've seen the other options provided by DanteAmor, as you posted about the same time
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,536
Members
449,037
Latest member
tmmotairi

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