+ Reply to Thread
Results 1 to 3 of 3

Need help to find the Sum of all the Cell in below

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, MS 365 (Windows 10 Pro 64-bit)
    Posts
    813

    Need help to find the Sum of all the Cell in below

    Hello All,
    Please help me to find the Sum for each cell in below in VBA code. Please take a look at sample attached for more detail.

    Regards,
    tt3
    Attached Files Attached Files

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Need help to find the Sum of all the Cell in below

    I think that this will do what you want

    Sub test()
        Dim oneArea As Range
        Dim LastPair As Range, PairFtn As String
        
        For Each oneArea In Range("AG:AG").SpecialCells(xlCellTypeConstants, xlNumbers).Areas
            With oneArea.Cells(1, 1).Offset(-1, 0)
                If .Offset(-1, 0).Value = vbNullString Then
                    If Not LastPair Is Nothing Then
                        LastPair.FormulaR1C1 = PairFtn
                    End If
                    Set LastPair = .Offset(-1, 0)
                    PairFtn = "=" & .Address(True, True, xlR1C1)
                Else
                    PairFtn = PairFtn & "+" & .Address(True, True, xlR1C1)
                End If
                .FormulaR1C1 = "=SUM(" & oneArea.Address(True, True, xlR1C1) & ")"
            End With
        Next oneArea
        If Not LastPair Is Nothing Then
            LastPair.FormulaR1C1 = PairFtn
        End If
    End Sub
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Forum Contributor
    Join Date
    08-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, MS 365 (Windows 10 Pro 64-bit)
    Posts
    813

    Re: Need help to find the Sum of all the Cell in below

    Hi Mikerickson,
    The code is perfect and is it possible to do another code in tab "Scenario1"? Thank you very much for your help.

    Regards,
    tt3
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Convert Find Parent Cell Macro to Find Dependent Cell
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-06-2016, 07:30 AM
  2. how to find a cell in excel and find all values in a row before that cell
    By DAVIDZZZ in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-18-2016, 10:04 AM
  3. how to find a cell in excel and find all values in a row before that cell
    By DAVIDZZZ in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-18-2016, 05:20 AM
  4. how to find a cell in excel and find all values in a row before that cell
    By DAVIDZZZ in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-18-2016, 05:17 AM
  5. how to find a cell in excel and find all values in a row before that cell
    By DAVIDZZZ in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-18-2016, 05:14 AM
  6. how to find a cell in excel and find all values in a row before that cell
    By DAVIDZZZ in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-18-2016, 03:15 AM
  7. Find blank cell, insert formula to find median of above cell range
    By lilyeye in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-05-2013, 11:58 AM

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