+ Reply to Thread
Results 1 to 13 of 13

VBA autofill/fill down formula multiple columns

Hybrid View

  1. #1
    Registered User
    Join Date
    07-11-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    15

    VBA autofill/fill down formula multiple columns

    Hi guys,

    I am trying create a macro that autofills a formula to the end for "D" "G" "J" "M" etc. in other words I want to create a loop which continues to do so. Attached file shows Column D8 that has a formula and it is autofilled to the last row. The real file has 1740 stocks which i want to autofill.

    Hope you guys can help me

    Kind regards
    Hewe
    Attached Files Attached Files
    Last edited by itshewe; 07-12-2014 at 06:32 AM. Reason: More details.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,686

    Re: VBA autofill/fill down formula multiple columns

    Try this:

    Option Explicit
    
    Sub Fill()
    Dim lr As Long
    lr = Range("E" & Rows.Count).End(xlUp).Row
    Range("D8").AutoFill Destination:=Range("D8:D" & lr)
    
    End Sub
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    07-11-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    15

    Re: VBA autofill/fill down formula multiple columns

    Unfortunately it did not work as it only fills one row and it does not stop at the end date of that row. Have you tested your self on the file i uploaded?

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: VBA autofill/fill down formula multiple columns

    Try this.
    Dim rng As Range
    Dim dst As Range
    
    
        Set rng = Range("D8,G8,J8,M8")
        Set dst = Intersect(rng.EntireColumn, Rows(8).Resize(Range("E" & Rows.Count).End(xlUp).Row - 7))
    
        dst.FillDown
    If posting code please use code tags, see here.

  5. #5
    Registered User
    Join Date
    07-11-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    15

    Re: VBA autofill/fill down formula multiple columns

    Quote Originally Posted by Norie View Post
    Try this.
    Dim rng As Range
    Dim dst As Range
    
    
        Set rng = Range("D8,G8,J8,M8")
        Set dst = Intersect(rng.EntireColumn, Rows(8).Resize(Range("E" & Rows.Count).End(xlUp).Row - 7))
    
        dst.FillDown
    Dear Norie,

    It worked, thank you so much! As the file I uploaded was only a sample, the real file has 1740 stocks which i need to perform this action upon. Is there any simpler way to set the range. To make it clear instead of writing ("D8,G8,J8,M8") to ("D8:M8")? Or else i would have to manually write from "D8" to "GRY8"

    Thanks again
    Hewe

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,686

    Re: VBA autofill/fill down formula multiple columns

    Have you tested your self on the file i uploaded?
    Yes. And it worked for me on your file.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: VBA autofill/fill down formula multiple columns

    If you used G8:M8 you would end up overwriting data.

    Is there any pattern to the columns you want autofilled?

  8. #8
    Registered User
    Join Date
    07-11-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    15

    Re: VBA autofill/fill down formula multiple columns

    Quote Originally Posted by Norie View Post
    If you used G8:M8 you would end up overwriting data.

    Is there any pattern to the columns you want autofilled?
    The pattern is that of the file, but imagine it continue to 1740 stocks.. every 8th row and 4th column after each other.

    ("D8,G8,J8,M8".....", GRY8")

  9. #9
    Registered User
    Join Date
    07-11-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    15

    Re: VBA autofill/fill down formula multiple columns

    Quote Originally Posted by Norie View Post
    If you used G8:M8 you would end up overwriting data.

    Is there any pattern to the columns you want autofilled?
    The pattern is that of the file, but imagine it continue to 1740 stocks.. every 8th row and 4th column after each other.

    ("D8,G8,J8,M8".....", GRY8")

  10. #10
    Registered User
    Join Date
    07-11-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    15

    Re: VBA autofill/fill down formula multiple columns

    hmm, the pattern is that of the file. but imagine it continue to 1740 stocks.. every 8th row and 4th column after each other.

    "D8,G8,J8,M8".....", GRY8")

  11. #11
    Registered User
    Join Date
    07-11-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    15

    Re: VBA autofill/fill down formula multiple columns

    internet problem =/ sorry!

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: VBA autofill/fill down formula multiple columns

    Isn't it more like every 3rd column, starting at column D?

  13. #13
    Registered User
    Join Date
    07-11-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    15

    Re: VBA autofill/fill down formula multiple columns

    Quote Originally Posted by Norie View Post
    Isn't it more like every 3rd column, starting at column D?
    yes sorry I meant the 3rd

+ 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. Replies: 8
    Last Post: 09-12-2016, 10:01 AM
  2. Macro VB for Formula Fill Through Several Rows in Multiple Columns
    By sanjeevpandey in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-25-2013, 11:04 AM
  3. [SOLVED] AutoFill Macro for a formula in one column fill-handled to multiple col/[variable] rows
    By kbspence in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-29-2012, 03:47 PM
  4. Fill cells with formula, one by one, AutoFill?
    By confusing in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-11-2012, 12:15 PM
  5. Replies: 3
    Last Post: 04-28-2005, 10:06 AM

Tags for this Thread

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