Hi,
I have defined Numrows as an integer.
I want to use the following code :-
But rather than M410, I want the code to copy down to "numrows"![]()
Selection.AutoFill Destination:=Range("M6:M410")
How can I code this?
Thanks in advance
Hi,
I have defined Numrows as an integer.
I want to use the following code :-
But rather than M410, I want the code to copy down to "numrows"![]()
Selection.AutoFill Destination:=Range("M6:M410")
How can I code this?
Thanks in advance
Last edited by bd528; 03-07-2010 at 04:59 AM.
Hi,
You can try
HTHSelection.AutoFill Destination:=Range("M6:M"&Numrows)
It's not clear what you're "filling" - formula/value etc... it's generally quicker to apply to a contiguous range using the below approach as opposed to AutoFill.
If we assume numrows is 10 then M6:M10 will assume the formula of the first cell in the selection.![]()
Range("M6:M" & numrows).Formula = Selection(1).Formula
If numrows is meant to represent the size of the vector rather than the literal end row number (implied by naming convention - ie number of rows) then you would use Resize
this would apply the formula to M6:M15 (10x1)![]()
Range("M6").Resize(numrows).Formula = Selection(1).Formula
If you're still having problems post a sample.
(we assume the sheet is unprotected etc...)
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
I have attached an example.
I want to copy the forumula down to the last row (based on the number of entries in column A)
I have used a seperate piece of code (not in the example) to count the number of entries in column A, which creates the integer "numrows". But if you know a better solution to counting them, please let me know.
Thanks.
Sorry, just looked at this...
![]()
Sub Example() Range(Cells(5,"A"),Cells(Rows.Count,"A").End(xlUp)).Offset(,12).Formula = "=K5-L5" End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks