+ Reply to Thread
Results 1 to 5 of 5

Dynamic Autofill

Hybrid View

  1. #1
    Registered User
    Join Date
    06-01-2015
    Location
    Derby, England
    MS-Off Ver
    2013
    Posts
    87

    Dynamic Autofill

    I'm pretty new to VBA programming and need some help with a dynamic autofill please.

    I have a spreadsheet that pulls in a dataset from a database which is similar to the area highlighted yellow on the attached mock up.

    Once this dataset is in my workbook I want to autofill a simple formula against each line. I've done this for the example attached with the Macro 'FillFormula'.

    My issue is that the size of the dataset can vary depending on some conditions and so the number of rows of data is dynamic. How do I edit my code so that the autofill always starts at cell D1 and keeps going until it hits a blank cell in column A then stops?

    Any and all help appreciated.

    Ed

    VBA Example.xlsm

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Dynamic Autofill

    Try this.....

    Sub InsertFormula()
    Dim lr As Long
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    Range("D1:D" & lr).Formula = "=IF(C1="""",""x"",C1-B1)"
    End Sub
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Dynamic Autofill

    Sub FillFormula()
        Dim rws As Long, rng As Range
    
        rws = Cells(Rows.Count, "A").End(xlUp).Row
        Set rng = Range("D1:D" & rws)
    
        rng = "=IF(RC[-1]="""",""x"",RC[-1]-RC[-2])"
    
    End Sub
    Checkout AutoFill Macro On YouTube

  4. #4
    Registered User
    Join Date
    06-01-2015
    Location
    Derby, England
    MS-Off Ver
    2013
    Posts
    87

    Re: Dynamic Autofill

    sktneer, davesexcel,

    Problem solved, Thank you.

    Ed

  5. #5
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Dynamic Autofill

    You're welcome Ed! Glad we could help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] AutoFill down dynamic range
    By Aaron092 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-15-2014, 11:37 AM
  2. [SOLVED] Autofill help with dynamic data
    By gdoode23 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-11-2013, 12:30 PM
  3. Dynamic Autofill
    By Dan27 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-19-2013, 10:30 AM
  4. Need help with dynamic autofill
    By oldmanexcel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-09-2013, 11:36 AM
  5. Autofill a Dynamic Selection
    By georgeanaprop in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-05-2012, 12:36 PM
  6. [SOLVED] Dynamic autofill VBA
    By Siglen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-31-2012, 01:10 AM
  7. [SOLVED] autofill with dynamic lists
    By Pontus SWE in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-13-2005, 02:05 PM

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