Insert formula with a Last Row Address reference

  • Hi,


    Can anyone please help me with this


    I am trying to insert a formula with a Last Row Address reference, and I can't get the wording correct on (M8:LastR)

    Code
    LastR = Range("M" & Cells(Rows.Count, "M").End(xlUp).Row).Address
    WS1.Range("M4").Formula = "=SUM(M8:LastR)"

    Edited once, last by Bah73 ().

  • Hello,


    Below is a macro to be tested

    Code
    Sub AddSumFormula()
    Dim WS1 As Worksheet
    Dim LastR As String
    Set WS1 = Sheet1
    LastR = WS1.Range("M" & Cells(Rows.Count, "M").End(xlUp).Row).Address(0, 0)
    WS1.Range("M4").Formula = "=SUM(M8:" & LastR & ")"
    End Sub

    Hope this will help

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

    Edited once, last by Carim ().

  • Bah73


    Since the Thread is now marked as Resolved ... my assumption would be you have been able to fix your problem ...???

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Not getting any feedback ... :(

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Hi Carim Thanks, sorry haven't been on this forum for a while.

    No problem .... :)


    But have you managed to solve your problem ...???


    Even 3 months later ... future readers would appreciate your feedback

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • No I didn't solve the problem for that one.


    The work around I used was to reference a range that would be greater than last would ever be.


    Like below


    I will try your code tonight when I get home.

    Code
    WS1.Range("M4").Formula = "=SUM(M8:M1000)"
  • Fair enough ...


    Let me thank you in advance for your future feedback :)

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • My interpretation of your Like is that the macro operates as requested ...


    So, now, I can mark your thread as solved ...

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Good to hear everything is sorted out :)

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!