Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Copy Formula to Last Needed Cell in Spreadsheet

Hello,

I have recorded a macro that will is supposed to copy a
formula from the first cell of a specified column to the
last cell that I need the formula to be copied to. When I
recorded the macro it put a specific range in the VBA
code, below is the code that was created during the record
macro process:
Sub CopyFormula()
'
' CopyFormula Macro
' Macro recorded 6/18/2004 by dy
'

'
Range("G2").Select
Application.CutCopyMode = False
Selection.Copy
Range("E3:G3").Select
Range("G3").Activate
Range(Selection, Selection.End(xlDown)).Select
Range("G3:G204").Select
ActiveSheet.Paste
Application.CutCopyMode = False
End Sub

The problem is that my range will get larger each day. So
tomorrow when I run My SQL script and then paste the data
into the Excel spreadsheet there may be 210 rows and this
VBA code will only copy the formula down to row 204 unless
I manually edit the code. How can I change this code so
that it will automatically know the last row that I need
to copy the formula to? Any help for a solution will be
greatly appreciated. Thank you.

Dave Y
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 77
Default Copy Formula to Last Needed Cell in Spreadsheet

Try this...

Range("G2").Copy
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
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
How do I copy a formula from one spreadsheet to another CHOCOLATE Excel Discussion (Misc queries) 2 December 3rd 08 06:23 PM
Excel formula to copy/paste formula needed please. colwyn Excel Discussion (Misc queries) 4 October 22nd 08 11:27 PM
help needed to write formula for excel spreadsheet colwyn Excel Discussion (Misc queries) 2 October 20th 08 03:50 PM
Formula needed for repetative spreadsheet amatur wkr Excel Worksheet Functions 3 April 30th 08 08:47 PM
Copy formula only from one spreadsheet to another LoriDe Excel Worksheet Functions 1 May 23rd 07 07:29 PM


All times are GMT +1. The time now is 07:37 PM.

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"