Dynamic Ranges

Danny54

Active Member
Joined
Jul 3, 2019
Messages
295
Office Version
  1. 365
Platform
  1. Windows
I have the statement below that I hardcoded the values I165:L165.

Each time I create this report I have to change the values (165 to the last row).

Is there a way to dynamically change them using xlUp since the column IXXX is the last row in column I and the L165 is the same row just over 4 cells.

Thanks


sourceBook.Sheets("Services").Range("I165:L165").Copy


Thanks
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
How about
Code:
sourceBook.Sheets("Services").Range("I" & Rows.Count).End(xlUp).Resize(, 4).Copy
 
Upvote 0
how would one modify this statement to get the cell info 4 rows above this range.

I tried something like this

sourceBook.Sheets("Services").Range("I" & Rows.Count).End(xlUp).Resize(, 4).Copy <- orginal
sourceBook.Sheets("Services").Range("I" & Rows.Count - 4).End(xlUp).Resize(, 4).Copy

Thanks
 
Upvote 0
Try
Code:
sourceBook.Sheets("Services").Range("I" & Rows.Count).End(xlUp).Offset(-4).Resize(, 4).Copy
 
Upvote 0
My pleasure & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
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