Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Copy Formula Down until last row

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default Copy Formula Down until last row

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Copy Formula Down until last row

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" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy formula result (text) only - without copying formula Mulberry Excel Discussion (Misc queries) 2 October 2nd 08 09:51 AM
I copy a formula and the results copy from the original cell brooklynsd Excel Discussion (Misc queries) 1 June 23rd 07 01:35 AM
copy formula down a column and have cell references change within formula brad New Users to Excel 5 May 13th 07 04:38 PM
Copy/Paste how to avoid the copy of formula cells w/o calc values Dennis Excel Discussion (Misc queries) 10 March 2nd 06 10:47 PM
Copy formula so destination displays formula as text Omunene Excel Discussion (Misc queries) 2 September 30th 05 06:28 PM


All times are GMT +1. The time now is 07:44 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"