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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
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,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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