Passing Row variable to row Auto fill logic

  • Thread starter Thread starter ExcelMonkey
  • Start date Start date
E

ExcelMonkey

I want to fill a range. I have a formula in J2 and I want to fill i
down to J10 (8 rows). When I record it, it looks like the code below.
However I want the number of rows to fill to be variable. How do
pass a row variable to this?

Sub Macro8()
Sheets("Paste Range").Select
Range("J2").Select
Selection.AutoFill Destination:=Range("J2:J10")
Type:=xlFillDefault

Range("J2:J10").Select
End Sub

Thank
 
LastRow controls how many rows to copy the contents of J2 to ........

Sub Macro8()
Dim LastRow As Long
LastRow = 10
Range("J2").AutoFill Destination:= _
Range(Cells(2, 10), Cells(LastRow, 10)), _
Type:=xlFillDefault
End Sub

Cheers
Nigel
 
Hi
something like
Sub Macro8()
dim lastrow
lastrow=30
Sheets("Paste Range").Range("J2").AutoFill _
Destination:=Range("J2:J" & lastrow), Type:=xlFillDefault
End Sub
 
ExcelMonkey > said:
I want to fill a range. I have a formula in J2 and I want to fill it
down to J10 (8 rows). When I record it, it looks like the code below.
However I want the number of rows to fill to be variable. How do I
pass a row variable to this?

Sub Macro8()
Sheets("Paste Range").Select
Range("J2").Select
Selection.AutoFill Destination:=Range("J2:J10"),
Type:=xlFillDefault

Range("J2:J10").Select
End Sub


Sub Macro8()

Sheets("Paste Range").Select
rstart = 2
rend = 10

Cells(rstart, "J").Select
Selection.AutoFill Destination:=Range(Cells(rstart, "J"), Cells(rend, "J")),
Type:=xlFillDefault
Range(Cells(rstart, "J"), Cells(rend, "J")).Select

End Sub
 
Sub Auto_Fill()
Dim lrow As Long
With ActiveSheet
lrow = Range("J" & Rows.Count).End(xlUp).Row
Range("J2:J" & lrow).FillDown
End With
End Sub

Gord Dibben 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

Back
Top