Consulting

Results 1 to 4 of 4

Thread: need help please creating a quick VBA solution for auto filling a dynamic range

  1. #1
    VBAX Regular
    Joined
    Dec 2014
    Posts
    31
    Location

    need help please creating a quick VBA solution for auto filling a dynamic range

    I need to copy down formulas in range S2:AH2. However, the number of rows these formulas are referencing in columns A:R, will always be variable. I know there's a way to use count or Dim a Variable range of rows ... but not sure how to implement or write the code.

    Hopefully, the attached image below is visible.

    Thanks!

    Steve

    dynamic range.jpg

    cross posted: http://www.mrexcel.com/forum/excel-q...lications.html

    This solved my problem:

    Sub LastRow()
    Dim lR As Long
    lR = Range("A:R").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Range("S2:AH" & lR).FillDown
    End Sub
    Last edited by sschwant; 06-16-2016 at 01:56 PM.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You can create a dynamic range name on the sheet using Formulas/Name Manager
    e.g. Create a name "List" with the formula
    =OFFSET(Sheet1!$A$1,1,0,COUNTA(Sheet1!$A:$A)-1,1)

    You can then refer to that list from any routine

    Sub Test()
    Range("List").Offset(, 18).FillDown
    End Sub
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Regular
    Joined
    Dec 2014
    Posts
    31
    Location
    Thanks mate! Interesting approach ... I may try that too. The other solution above also worked.

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Of course you can always just double-click the fill button.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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