+ Reply to Thread
Results 1 to 3 of 3

Macro for Summing Rows above blank cell until previous blank cell

  1. #1
    Registered User
    Join Date
    04-19-2018
    Location
    London
    MS-Off Ver
    10
    Posts
    5

    Macro for Summing Rows above blank cell until previous blank cell

    Hi all VBA pro's.

    I don't code VBA per se but rather record macro's or help search the forum for code that I can copy and tweak as necessary.

    Think I am nearly there with this query having extensively searched forum but just can't find exactly what I require.

    I have numerical data going from C10:AC600 and I already have got a code to insert blank rows where required.

    So the below code does works BUT I have the following 2 issues that I kindly request anyone's help on:

    i) How do I extend the code to perform same "Sum" across all columns up to AC?
    ii) How can I get the code to show "Sum" formula rather than hard numbers? Seems I need to add something like this, .Formula = "=sum(" & Rng.Address & ")"


    Dim ws As Worksheet
    Set ws = Worksheets("sheet1")

    Dim FirstCell As Range
    Set FirstCell = ws.Range("C10")

    Dim VeryLastCell As Range
    Set VeryLastCell = ws.Cells(ws.Rows.Count, "C").End(xlUp)

    Do
    Dim LastCell As Range
    If FirstCell.Offset(1) = vbNullString Then
    Set LastCell = FirstCell
    Else
    Set LastCell = FirstCell.End(xlDown)
    End If

    With LastCell.Offset(1, 0)
    .Value = Application.WorksheetFunction.Sum(ws.Range(FirstCell, LastCell))
    .Interior.Color = RGB(255, 255, 0)
    End With

    Set FirstCell = LastCell.Offset(2, 0)

    Loop While FirstCell.Row < VeryLastCell.Row
    End Sub


    Any help much appreciated.

    Tks,
    Nick

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Macro for Summing Rows above blank cell until previous blank cell

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    04-19-2018
    Location
    London
    MS-Off Ver
    10
    Posts
    5

    Re: Macro for Summing Rows above blank cell until previous blank cell

    That is absolute magic! Thank you.

+ 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. [SOLVED] summing from a blank cell upwards to the next blank cell
    By Travisty in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 02-04-2017, 04:53 AM
  2. Display blank cell if previous cell is blank in formula
    By Brent951 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-29-2016, 03:34 PM
  3. Replies: 1
    Last Post: 07-22-2016, 04:03 PM
  4. [SOLVED] Find certain word, copy and paste cell in previous row if previous row is blank
    By steven_e in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-19-2013, 12:53 PM
  5. Mac Excel: Hiding rows if cell blank, when being blank depends on a conditional formula
    By lee_5_5 in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 0
    Last Post: 06-06-2013, 11:25 PM
  6. [SOLVED] VBA code to insert 1 or 2 rows, 2 if next cell not blank,1 if next cell blank but 2nd not
    By lee.pulford in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-11-2012, 04:06 PM
  7. How to hide rows based on whether cell in previous row is blank
    By frankienap in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-13-2012, 05:22 PM

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