ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Autofill dynamic no. of rows and columns (https://www.excelbanter.com/excel-programming/342331-autofill-dynamic-no-rows-columns.html)

[email protected]

Autofill dynamic no. of rows and columns
 
Hi,

I'm trying to copy the formulas from the first row starting from B2 to
some finite column number and applying these formulas (which may be
different) to a dynamic number of rows. In other words, the "BK6" is
not a fixed value. How can I achieve this? Thanks!


Range("B2").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.AutoFill Destination:=Range("B2:BK6"), _Type:=xlFillDefault


Bob Phillips[_6_]

Autofill dynamic no. of rows and columns
 
Do you want this final row to be user specified?

Dim iLastCol As Long
Dim iLastRow As Long

iLastCol = Cells(2, Columns.Count).End(xlToLeft).Column
iLastRow = InputBox("specify last row #")
Range("B2", Cells(2, iLastCol)).AutoFill _
Destination:=Range("B2", Cells(iLastRow, iLastCol)),
Type:=xlFillDefault


--
HTH

Bob Phillips

wrote in message
ps.com...
Hi,

I'm trying to copy the formulas from the first row starting from B2 to
some finite column number and applying these formulas (which may be
different) to a dynamic number of rows. In other words, the "BK6" is
not a fixed value. How can I achieve this? Thanks!


Range("B2").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.AutoFill Destination:=Range("B2:BK6"), _Type:=xlFillDefault




[email protected]

Autofill dynamic no. of rows and columns
 
Nope. It should be determined through a count of the first column's
number of rows. Will try out your suggestion. Thanks!


Bob Phillips[_6_]

Autofill dynamic no. of rows and columns
 
Okay, then use this

Dim iLastCol As Long
Dim iLastRow As Long

iLastCol = Cells(2, Columns.Count).End(xlToLeft).Column
iLastRow = Cells(Rows.Count,"B").End(xlUp).Row
Range("B2", Cells(2, iLastCol)).AutoFill _
Destination:=Range("B2", Cells(iLastRow, iLastCol)), _
Type:=xlFillDefault

--
HTH

Bob Phillips

wrote in message
oups.com...
Nope. It should be determined through a count of the first column's
number of rows. Will try out your suggestion. Thanks!




[email protected]

Autofill dynamic no. of rows and columns
 
Thanks Bob, works like a charm.

Yeh Wei



All times are GMT +1. The time now is 12:26 AM.

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