Macro to copy a data set with unknown number of rows

EricB9

New Member
Joined
Apr 10, 2014
Messages
6
I have data in multiple excel workbooks that I am building a macro to bring in to a single workbook. The data is a list of tenants and move-in dates etc. The data covers columns C:X and begins at row 9. The problem is I need the macro to determine how many rows are in the data set so I know how far to copy down. Basically I need to copy cells C9:X??. Any help would be much appreciated. Column D will always have data for the rows that will need to be copied if that helps.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Try:
Dim lastRow as Long
lastRow = Range("D" & Rows.Count).End(xlUp).Row

Range("C9:X" & lastRow) is the range you want to copy
 
Upvote 0
Thanks for your response. Unfortunately It is copying more than I want it to. I think the problem is that the data I need to copy will be 15 rows or so, then 100 blank rows, then totals at the bottom. Unfortunately this coding is copying everything down through the totals when I only want to copy the top 15+ rows that have the raw data in them. Any ideas would be great.
 
Upvote 0

Forum statistics

Threads
1,223,627
Messages
6,173,420
Members
452,514
Latest member
cjkelly15

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