• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Sum to Dynamic Last Column

eeng

New Member
Hi

I need the VBA for sum with dynamic last column range

The Data may be increase or decrease in column (unknown range), but I need the sum formula in the last column.

Kindly provide the VBA Code
 

Attachments

AlanSidman

Well-Known Member
Code:
Option Explicit

Sub SumL17()

    Dim lr As Long, lc As Long
    lr = Range("A" & Rows.Count).End(xlUp).Row
    lc = Cells(1, Columns.Count).End(xlToLeft).Column
    Range("L17") = WorksheetFunction.Sum(Range(Cells(2, lc), Cells(lr, lc)))


End Sub
 

eeng

New Member
Code:
Option Explicit

Sub SumL17()

    Dim lr As Long, lc As Long
    lr = Range("A" & Rows.Count).End(xlUp).Row
    lc = Cells(1, Columns.Count).End(xlToLeft).Column
    Range("L17") = WorksheetFunction.Sum(Range(Cells(2, lc), Cells(lr, lc)))


End Sub
thanks .. it work....
 

eeng

New Member
Code:
Option Explicit

Sub SumL17()

    Dim lr As Long, lc As Long
    lr = Range("A" & Rows.Count).End(xlUp).Row
    lc = Cells(1, Columns.Count).End(xlToLeft).Column
    Range("L17") = WorksheetFunction.Sum(Range(Cells(2, lc), Cells(lr, lc)))


End Sub

How the code if the data on different workbook?
(the data on Workbook A, and the result on workbook B)

Thanks
 
Top