+ Reply to Thread
Results 1 to 5 of 5

Autofill dynamic no. of rows and columns

Hybrid View

  1. #1
    YehWei@gmail.com
    Guest

    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


  2. #2
    Bob Phillips
    Guest

    Re: 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

    <YehWei@gmail.com> wrote in message
    news:1128935911.728112.6910@g49g2000cwa.googlegroups.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
    >




  3. #3
    YehWei@gmail.com
    Guest

    Re: 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!


  4. #4
    Bob Phillips
    Guest

    Re: 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

    <YehWei@gmail.com> wrote in message
    news:1128944090.905042.173350@o13g2000cwo.googlegroups.com...
    > Nope. It should be determined through a count of the first column's
    > number of rows. Will try out your suggestion. Thanks!
    >




  5. #5
    YehWei@gmail.com
    Guest

    Re: Autofill dynamic no. of rows and columns

    Thanks Bob, works like a charm.

    Yeh Wei


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1