use variable value in a range reference?

J

JCIrish

My code is

Dim myformulaTotalRows As Integer
Dim mylastFormulaRow As Integer

With Range("formulaCells") 'named range
totalRows = .Rows.Count
lastRow = .Rows(totalRows).Row
End With

myformulaTotalRows = totalRows
mylastFormulaRow = lastRow

Is there a way to use "mylastFormulaRow" in a statement like
Range("C6").select where the row number 6 can be replaced by
"mylastFormulaRow"?

I want to use the selected cell as the first argument in a .filldown statement

Thanks for any help
 
D

Don Guillett

Sub fillitdown()
'Range("e1").AutoFill Range("e1:e4")
dim lr as long
lr = Cells(Rows.Count, "e").End(xlUp).Row
Cells(lr, "e").AutoFill Cells(lr, "e").Resize(4)
End Sub
 
J

JCIrish

Thanks, Dave. I must have tried ten things similar to your solution except
including the &. I appreciate the help.
 
J

JCIrish

Thank you,Don. That's a more elegant way to go than my Sub. I'm sure it will
be useful to me in many similar situations.
 

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