View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Dave Y[_3_] Dave Y[_3_] is offline
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