Macro to Copy formula to end of data
Results 1 to 5 of 5

Thread: Macro to Copy formula to end of data
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Posts
    59
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Macro to Copy formula to end of data

    Hi...strange question...I have a macro that I created that inserts a row, adds a formula. Now I need to copy the formula down to the last row. (You know, like when you double click in the corner of a cell and it copies the formula to the last row with data in the adjoining column).

    When I double click while recording my macro it just references the actual column and row number, but it won't aways be the same as the spreadsheet grows daily. So I need a "copy to last row" formula for the macro. But the last row will change everytime I run it.

    I hope this makes sense. I am new to this macro stuff!! But trying to learn!

  2. #2
    Legend VoG's Avatar
    Join Date
    Jun 2002
    Location
    127.0.0.1
    Posts
    63,651
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    8 Thread(s)

    Default Re: Macro to Copy formula to end of data

    To fill down a formula in F2

    Code:
    Sub Myfill()
    Dim LR As Long
    LR = ActiveSheet.UsedRange.Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    Range("F2").AutoFill Destination:=Range("F2:F" & LR)
    End Sub
    HTH, Peter
    Please test any code on a copy of your workbook.

  3. #3
    Board Regular
    Join Date
    Feb 2002
    Posts
    59
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Re: Macro to Copy formula to end of data

    Awesome .... you are my hero today!

  4. #4
    New Member
    Join Date
    May 2017
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Macro to Copy formula to end of data

    Hi - I am trying to do a similar thing, but don't understand Macro code well enough to know how to insert it into the code. I am trying to fill down the following formula in column F, using column A to find last row.

    =IF(F2>0, "YES", "").

    Do I complete recording the macro, then go into the code and insert it? Where does it go? Obviously, I am a newbie.

  5. #5
    New Member
    Join Date
    Jul 2019
    Posts
    1
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Macro to Copy formula to end of data

    Quote Originally Posted by VoG View Post
    To fill down a formula in F2

    Code:
    Sub Myfill()
    Dim LR As Long
    LR = ActiveSheet.UsedRange.Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    Range("F2").AutoFill Destination:=Range("F2:F" & LR)
    End Sub
    This is great!

    How would I define sheet names? I need these lines to run on two different sheets with different data.

    Thanks,
    D

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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