ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using Autofill knowing row and column number (https://www.excelbanter.com/excel-programming/328096-using-autofill-knowing-row-column-number.html)

Fred Smith

Using Autofill knowing row and column number
 
I want to do the programmatic equivalent of dragging the fill handle down
one row. I know the row and column number of the destination cell. I tried:

..cells(Nextrow - 1, 2).autofill destination=.cells(Nextrow, 2)

but I got a range error. What's the correct syntax? Also, what's the syntax
if I want to fill a range of cells (eg, columns 12 to17)?

--
Thanks,
Fred





Tom Ogilvy

Using Autofill knowing row and column number
 
Sub AA()
Dim NextRow As Long
Dim rng As Range
NextRow = 10
With ActiveSheet
Set rng = .Range(.Cells(NextRow - 1, 2), .Cells(NextRow, 2))
.Cells(NextRow - 1, 2).AutoFill Destination:=rng
End With
End Sub

--
Regards,
Tom Ogilvy




"Fred Smith" wrote in message
...
I want to do the programmatic equivalent of dragging the fill handle down
one row. I know the row and column number of the destination cell. I

tried:

.cells(Nextrow - 1, 2).autofill destination=.cells(Nextrow, 2)

but I got a range error. What's the correct syntax? Also, what's the

syntax
if I want to fill a range of cells (eg, columns 12 to17)?

--
Thanks,
Fred







Dave Peterson[_5_]

Using Autofill knowing row and column number
 
How about:

Option Explicit
Sub testme01()
Dim NextRow As Long
NextRow = 3 'test data only
With ActiveSheet
.Cells(NextRow - 1, 2).AutoFill _
Destination:=.Cells(NextRow - 1, 2).Resize(2, 1)
End With
End Sub



Fred Smith wrote:

I want to do the programmatic equivalent of dragging the fill handle down
one row. I know the row and column number of the destination cell. I tried:

.cells(Nextrow - 1, 2).autofill destination=.cells(Nextrow, 2)

but I got a range error. What's the correct syntax? Also, what's the syntax
if I want to fill a range of cells (eg, columns 12 to17)?

--
Thanks,
Fred


--

Dave Peterson


All times are GMT +1. The time now is 09:38 AM.

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