Consulting

Results 1 to 5 of 5

Thread: VBA: Copy row to the last line of data

  1. #1

    VBA: Copy row to the last line of data

    Hi everyone, Still new! but learning with everyone's help :-)

    I have data in columns D and G and I am adding a formula in Columns A, B, C, E, F and J. I want to make sure the formula columns go to the end of the data in Column D when I copy it down.

    Example:

    See attached

    I want columns to use column D to know where to copy the formula down to.


    thanks!!
    Attached Files Attached Files

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Something like

    Dim lastrow As Long
    
        With ActiveSheet
        
            lastrow = .Cells(.Rows.Count, "D").End(xlUp).Row
            .Cells(3, "A").Resize(lastrow - 2).Formula = "=myformula1"
            .Cells(3, "B").Resize(lastrow - 2).Formula = "=myformula2"
            'etc
        End With
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Sub Test()
    Dim lastrow As Long
    Dim Arr, a
    Arr = Array("A", "B", "C", "E", "F", "J")
    With ActiveSheet
        lastrow = .Cells(.Rows.Count, "D").End(xlUp).Row
        For Each a In Arr
            .Cells(3, a).Resize(lastrow - 2).FillDown
        Next a
    End With
    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'

  4. #4
    Thank you!!

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    If this is answered please mark it so using Thread Tools dropdown.
    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
  •