You are here:

Excel/Copy Formula until Last Row

Advertisement


Question
Dear Bob,

I saw you answering the question pasted below. I was wondering how to do this when having the in this case A column in a different sheet then in this case the H, V and W columns. I somehow don't seem to get the syntax right.

Thanks,
Ampi

***

I have formulas in row 2 in the cells: H2, V2, & W2. I need a code to copy down the formulas till last row based on column A.
I have the follwoing code, but it works only for column H, please suggest changes , or you can give some better code than this one:

Sub CopyFormula()
Dim LastRow As Long
With Worksheets("Data")
LastRow = Worksheets("Data").Cells(Rows.Count, "A").End(xlUp).Row
.Range("H2").AutoFill Destination:=.Range("H2:H" & LastRow) _
, Type:=xlFillDefault
End With
End Sub

Answer
Sub CopyFormula()
Dim LastRow As Long
With Worksheets("Data")
LastRow = Worksheets("Data").Cells(Rows.Count, "A").End(xlUp).Row
.Range("H2").AutoFill Destination:=.Range("H2:H" & LastRow) _
, Type:=xlFillDefault
.Range("V2").AutoFill Destination:=.Range("V2:V" & LastRow) _
, Type:=xlFillDefault
.Range("W2").AutoFill Destination:=.Range("W2:W" & LastRow) _
, Type:=xlFillDefault

End With
End Sub
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Bob Umlas

Expertise

I`m a Microsoft Excel MVP (Most Valuable Professional) and have been since the inception of the program in 1995. I can answer every kind of Excel question except: API, Importing/exporting to other programs (powerpoint, word,...) Also check out my in-person training link at http://www.thumbtack.com/ny/new-york/excel-training/

Experience

Worked with MS Excel since version 0.99 (on the Mac!). Was contributing editor to Excellence Magazine, having written >300 articles. John Walkenbach said of me "I finally met someone who knows as much about Excel as I do."

Publications
Excellence, The Expert, Microsoft

Education/Credentials
BA in math, Hofstra University, 1965

Awards and Honors
MVP
Led sessions for the Convergence 2004-2006 seminar on Excel tips & tricks

©2016 About.com. All rights reserved.