PC Review


Reply
Thread Tools Rate Thread

Copy Formula Down until last row

 
 
mickjjuk
Guest
Posts: n/a
 
      7th Dec 2009
How would I copy a formula down a column until the last row.
I have data being output to a workbook and the number of rows change each
time I run the report. In cell M2 I wish to enter the formula =sum(L2-K2)
and then copy this down to the end cell in column M, so M3 = =sum(L3-K3), M4
= =sum(L4-K4) and so on
 
Reply With Quote
 
 
 
 
marcus
Guest
Posts: n/a
 
      7th Dec 2009
Hi Mick

Try this for size. Should do what you want.

take care

Marcus


Sub CopytoLast()
Dim lw As Long

lw = Range("L" & Rows.Count).End(xlUp).Row
Range("M2").Value = "=L2-K2"
Range("M2:M" & lw).FillDown

End Sub

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      7th Dec 2009
Here is another way to do it (note that FillDown is not used)...

Sub CopytoLast()
Dim LastRow As Long
Columns("M").ClearContents
LastRow = Cells(Rows.Count, "L").End(xlUp).Row
Range("M2:M" & LastRow).Formula = "=L2-K2"
End Sub

Also note that I clear the contents of Column M before putting the formula
into the cells... I do this just in case the data Column L is less than it
was the previous time the macro was run.

--
Rick (MVP - Excel)


"mickjjuk" <(E-Mail Removed)> wrote in message
news:EF2151DE-807D-422D-803D-(E-Mail Removed)...
> How would I copy a formula down a column until the last row.
> I have data being output to a workbook and the number of rows change each
> time I run the report. In cell M2 I wish to enter the formula
> =sum(L2-K2)
> and then copy this down to the end cell in column M, so M3 = =sum(L3-K3),
> M4
> = =sum(L4-K4) and so on


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel formula to copy/paste formula needed please. colwyn Microsoft Excel Misc 4 22nd Oct 2008 11:27 PM
copy formula result (text) only - without copying formula Mulberry Microsoft Excel Misc 2 2nd Oct 2008 09:51 AM
I copy a formula and the results copy from the original cell =?Utf-8?B?YnJvb2tseW5zZA==?= Microsoft Excel Misc 1 23rd Jun 2007 01:35 AM
copy formula down a column and have cell references change within formula brad Microsoft Excel New Users 5 13th May 2007 04:38 PM
Copy/Paste how to avoid the copy of formula cells w/o calc values =?Utf-8?B?RGVubmlz?= Microsoft Excel Misc 10 2nd Mar 2006 10:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:17 AM.