+ Reply to Thread
Results 1 to 3 of 3

Sum Columns:R1C1 notation

  1. #1
    Zone
    Guest

    Sum Columns:R1C1 notation

    Another post got me interested in this. It's desired to put the sum at
    the bottom of columns C through E. I want to put the sum there, not a
    formula. I thought some kind of R1C1 notation would be necessary, but
    I got this method from help. The notation seems odd but it works well.
    Is this the best way to do it?
    TIA, James

    Sub SumCols()
    Dim k As Integer, LastRow As Long, myRg As Range
    For k = 3 To 5
    LastRow = Cells(65536, k).End(xlUp).Row
    Set myRg = Range(Cells(2, k), Cells(LastRow, k))
    Cells(LastRow + 1, k) = Application.WorksheetFunction.Sum(myRg)
    Next k
    End Sub


  2. #2
    Bob Phillips
    Guest

    re: Sum Columns:R1C1 notation

    Nothing wring with that per se.

    You shouldn't hard-code the number of rows though, and you could also use
    Resize

    Sub SumCols()
    Dim k As Integer, LastRow As Long, myRg As Range
    For k = 3 To 5
    LastRow = Cells(Rows.Count, k).End(xlUp).Row
    Set myRg = Cells(2, k).Resize(LastRow -1)
    Cells(LastRow + 1, k) = Application.WorksheetFunction.Sum(myRg)
    Next k
    End Sub

    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "Zone" <jkend69315@aol.com> wrote in message
    news:1153142518.762572.236490@s13g2000cwa.googlegroups.com...
    > Another post got me interested in this. It's desired to put the sum at
    > the bottom of columns C through E. I want to put the sum there, not a
    > formula. I thought some kind of R1C1 notation would be necessary, but
    > I got this method from help. The notation seems odd but it works well.
    > Is this the best way to do it?
    > TIA, James
    >
    > Sub SumCols()
    > Dim k As Integer, LastRow As Long, myRg As Range
    > For k = 3 To 5
    > LastRow = Cells(65536, k).End(xlUp).Row
    > Set myRg = Range(Cells(2, k), Cells(LastRow, k))
    > Cells(LastRow + 1, k) = Application.WorksheetFunction.Sum(myRg)
    > Next k
    > End Sub
    >




  3. #3
    Zone
    Guest

    re: Sum Columns:R1C1 notation

    Thanks, Bob. Interesting. Will study. James
    Bob Phillips wrote:
    > Nothing wring with that per se.
    >
    > You shouldn't hard-code the number of rows though, and you could also use
    > Resize
    >
    > Sub SumCols()
    > Dim k As Integer, LastRow As Long, myRg As Range
    > For k = 3 To 5
    > LastRow = Cells(Rows.Count, k).End(xlUp).Row
    > Set myRg = Cells(2, k).Resize(LastRow -1)
    > Cells(LastRow + 1, k) = Application.WorksheetFunction.Sum(myRg)
    > Next k
    > End Sub
    >
    > --
    > HTH
    >
    > Bob Phillips
    >
    > (replace somewhere in email address with gmail if mailing direct)
    >
    > "Zone" <jkend69315@aol.com> wrote in message
    > news:1153142518.762572.236490@s13g2000cwa.googlegroups.com...
    > > Another post got me interested in this. It's desired to put the sum at
    > > the bottom of columns C through E. I want to put the sum there, not a
    > > formula. I thought some kind of R1C1 notation would be necessary, but
    > > I got this method from help. The notation seems odd but it works well.
    > > Is this the best way to do it?
    > > TIA, James
    > >
    > > Sub SumCols()
    > > Dim k As Integer, LastRow As Long, myRg As Range
    > > For k = 3 To 5
    > > LastRow = Cells(65536, k).End(xlUp).Row
    > > Set myRg = Range(Cells(2, k), Cells(LastRow, k))
    > > Cells(LastRow + 1, k) = Application.WorksheetFunction.Sum(myRg)
    > > Next k
    > > End Sub
    > >



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1