• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Not able to get dynamic range.

Jagdev Singh

Active Member
Hi Experts

I want to capture the used range from a sheet. The code which I am using right now is

Code:
Dim LastRow1 As Long
   
    LastRow1 = ActiveSheet.UsedRange.Rows.Count
Range("$B$5:$P$5" & LastRow1).Select

My data range starts from B5

I am getting the exact count when I run the code and put my cursor on LastRow1 (55 rows), but the range gets selected till 554.

Am I doing something wrong here.

Regards,
JD
 
Try:

Code:
LastRow1 = Range("B" & Rows.Count).End(xlUp).Row
Range("$B$5:$P$" & LastRow1).Select

Choose a Column ie: "B" that is guaranteed to have the last piece of data in it
 

Hi !

UsedRange is not the filled data range but also the used cells
(format, borders, …) even with empty data ! :cool:

MsgBox ActiveSheet.UsedRange.Address

See also CurrentRegion.
 
Back
Top