Dynamic copying of rows

V

ville.jokela

This might be very easy question, but very hard for me. I try to do VBA
code where I copy one formula to rows. When I record a macro I get
this code:


Sub uusikopsaus()

Range("C6").Select
Selection.AutoFill Destination:=Range("C6:C20"),
Type:=xlFillDefault
Range("C6:C20").Select
End Sub


This code is okay, but how I should change it such way that range
function get parameters from COUNT function. This is pseudocode, but
idea is this kind of:

Selection.AutoFill Destination:=Range("C6:C[COUNT(C:C)]")

Thanks in advance
 
D

Dave Peterson

If there's no data in column C, then the count (probably countA()) wouldn't
work. But if there's data in column C, then you're gonna overwrite it?

If you can pick out a column that can be used to determine the last row number,
you can do something like:

dim LastRow as long

with activesheet
lastrow = .cells(.rows.count,"A").end(xlup).row 'I used column A
.range("c6").autofill destination:=.range("c6:c" & lastrow)
end with



This might be very easy question, but very hard for me. I try to do VBA
code where I copy one formula to rows. When I record a macro I get
this code:

Sub uusikopsaus()

Range("C6").Select
Selection.AutoFill Destination:=Range("C6:C20"),
Type:=xlFillDefault
Range("C6:C20").Select
End Sub

This code is okay, but how I should change it such way that range
function get parameters from COUNT function. This is pseudocode, but
idea is this kind of:

Selection.AutoFill Destination:=Range("C6:C[COUNT(C:C)]")

Thanks in advance
 

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