Find end of column and paste formula in range

M

MGS

I am extracting data from a database into Excel. My colums are constant, but
number of rows vary.

I need to copy a formula from AC2 down to the last row in that column.

Thanks for the help!
 
G

Gary''s Student

Try this small macro:

Sub CopyFormula()
Dim nLastRow As Long, destynation As String
Set r = ActiveSheet.UsedRange
nLastRow = r.Rows.Count + r.Row - 1
destynation = "AC3:AC" & nLastRow
Range("AC2").Copy Range(destynation)
End Sub
 
G

Gord Dibben

Will the formula already be in AC2?

Is there any adjacent column that will extend to last row?

I will assume there is a formula and use column AB to determine last row.

Sub Auto_Fill()
Dim Lrow As Long
With ActiveSheet
Lrow = .Range("AB" & Rows.Count).End(xlUp).Row
.Range("AC2:AC" & Lrow).FillDown
End With
End Sub


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top