Dynamic range help

Gromace

New Member
Joined
Jan 11, 2011
Messages
15
Hello,

I have the following code in a macro, in Excel 2007.

Range("M5").Select
Selection.Copy
Range("M5:M18264").Select
ActiveSheet.Paste


I currently have over 18,000 cells in the range, but the exact number will change monthly. What is the most effective way to select my range, without knowing the exact number of cells? Is there a function that can do this? If column A contains data, I want to include that row number in the range.

Thanks in advance for your help!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

sanrv1f

MrExcel MVP
Joined
Jan 1, 2009
Messages
3,474
Office Version
  1. 2016
Platform
  1. Windows
First, you dont have to select a range to do Copy or Paste,

Code:
Range("M5:M" & Range("A" & Rows.Count).End(xlUp).Row).FillDown
 

Gromace

New Member
Joined
Jan 11, 2011
Messages
15
Sankar,

Thank you for your quick response! Your suggestion worked in place of the code I posted, but I have one other request. Could you explain what is going on with your code? That would help me learn it and understand what is going on. I also have similar code that I need to modify. Once I have completed the filldown, I would like to select the entire row and copy, pastespecial value. Can I use the same type of code you suggested?

Thanks again!

Gromace
 

Forum statistics

Threads
1,141,844
Messages
5,708,928
Members
421,599
Latest member
santosh234

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
Top