Consulting

Results 1 to 5 of 5

Thread: Copy formula/row range down to a value specified by another cell?

  1. #1
    VBAX Newbie
    Joined
    Jan 2018
    Posts
    3
    Location

    Copy formula/row range down to a value specified by another cell?

    Hello all,

    I am trying to copy a row of cells/formulas down x amount of times based on a cell value.

    For example; Range ("A6:J6") x number of times (specified by a formula in cell "D3"-1), beneath "A6:J6". Can someone help? I have just started to learn about bits of VBA so don't quite fully understand destination ranges currently. Any help would be appreciated.

    excel help.jpg

    So A6:J6 needs to applied down to row A6+2:J6+2? Hope that makes sense.

  2. #2
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,192
    Location
    Maybe something like:

    Sub FillTo()
    
        Dim FillTo As Long
        
        FillTo = Range("D3").Value - 1
        
        Range("A6:J6").AutoFill Range("A6:J" & 6 + FillTo)
    
    
    End Sub
    Maybe someone else has something more efficient or another way round things..

    Hope this helps
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved

    Excel 365, Version 2403, Build 17425.20146

  3. #3
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Sub test()
         
        With Range("A6:J6")
            .Copy .Resize(Range("D3").Value)
        End With
           
    End Sub

  4. #4
    VBAX Newbie
    Joined
    Jan 2018
    Posts
    3
    Location
    Quote Originally Posted by mana View Post
    Sub test()
         
        With Range("A6:J6")
            .Copy .Resize(Range("D3").Value)
        End With
           
    End Sub
    works great! thanks for the swift reply

  5. #5
    VBAX Newbie
    Joined
    Jan 2018
    Posts
    3
    Location
    Quote Originally Posted by georgiboy View Post
    Maybe something like:

    Sub FillTo()
    
        Dim FillTo As Long
        
        FillTo = Range("D3").Value - 1
        
        Range("A6:J6").AutoFill Range("A6:J" & 6 + FillTo)
    
    
    End Sub
    Maybe someone else has something more efficient or another way round things..

    Hope this helps
    thanks! works

Posting Permissions

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