ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Dynamic copying of rows (https://www.excelbanter.com/excel-programming/358106-dynamic-copying-rows.html)

[email protected]

Dynamic copying of rows
 
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


Dave Peterson

Dynamic copying of rows
 
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



wrote:

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


--

Dave Peterson


All times are GMT +1. The time now is 04:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com