Consulting

Results 1 to 6 of 6

Thread: sum cells above every blank cell

  1. #1
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location

    sum cells above every blank cell

    Hello i have this VBA code but it will sum in and put the value in the latest blank cell i need sum and paste the value in top blank cell like the the attached images
    Sub SumAreas()
    
    Dim Area As Range
    For Each Area In Range("G1", Range("G" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants).Areas
      With Area
        Cells(.Row + .Rows.Count, 7).Value = Evaluate("=Sum(G" & .Row & ":G" & .Row + .Rows.Count - 1 & ")")
        Cells(.Row + .Rows.Count, 7).Font.Bold = True
      End With
    Next Area
    End Sub
    Result.jpg

  2. #2
    VBAX Newbie
    Joined
    Nov 2017
    Posts
    1
    Location
    is there have worksheet function call "sumif" can fulfill your request?

  3. #3
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    Sorry I do not understand what your mean ?

  4. #4
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Sub test()
        Dim a As Range
        
        For Each a In Columns(7).SpecialCells(xlCellTypeConstants).Areas
            With a(1).Offset(-1)
                .Value = WorksheetFunction.Sum(a)
                .Font.Bold = True
            End With
        Next
        
    End Sub
    マナ

  5. #5
    Hello Try this code
    Sub SumAreasTest()
        Dim area As Range
        
        For Each area In Range("G1", Range("G" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants).Areas
            With area
                Cells(.Row - 1, 7).Value = Evaluate("=Sum(G" & .Row & ":G" & .Row + .Rows.Count - 1 & ")")
                Cells(.Row - 1, 7).Font.Bold = True
            End With
        Next area
    End Sub

  6. #6
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location
    Appreciate for your help .

Posting Permissions

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