+ Reply to Thread
Results 1 to 3 of 3

Excel VBA: Find empty cells and Sum Cells before it

Hybrid View

hampton06 Excel VBA: Find empty cells... 08-14-2012, 04:59 PM
MaczaQ Re: Excel VBA: Find empty... 08-14-2012, 05:17 PM
hampton06 Re: Excel VBA: Find empty... 08-15-2012, 04:36 PM
  1. #1
    Registered User
    Join Date
    08-02-2012
    Location
    North Haven, CT
    MS-Off Ver
    Excel 2010
    Posts
    3

    Excel VBA: Find empty cells and Sum Cells before it

    I am trying to set up a macro that will scroll through a row of data on my worksheet until it hits an empty cell, and then it will add up the cell values before that cell and enter that value into the empty cell. Then it will continue going until the end of the row. I was able to find a sample of code that does this exact function but with the data in a single column, and not a single row. And I have tried to just change the values around a little bit, but am not having any luck. For example, my data looks similar to this...

    1, empty, 1, 1, empty, 1, 1, 1, empty

    Here is the code that I got working for the values if they are in a single column..
    Sub InsertTotals()
    Dim StartRow As Integer
    Dim EndRow As Integer
    
    StartRow = 1
    EndRow = Range("A20").End(xlUp).Offset(1, 0).Row
    For i = StartRow To EndRow
    If Cells(i, "A") = "" And i > StartRow Then
    Cells(i, "A").Formula = "=SUM(A" & StartRow & ":A" & i - 1 & ")"
    StartRow = i + 1
    End If
    Next
    
    End Sub

  2. #2
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Excel VBA: Find empty cells and Sum Cells before it

    hi,

    check this thread: http://www.excelforum.com/excel-prog...html?p=2873581
    It is for average but I hope You will find it useful
    Best Regards
    MaczaQ
    ---------------------------------------------------------------------------------------------------------------------------
    If you are satisfied with the solution(s) provided, please mark your thread as Solved
    If you are pleased with my answer consider to rate it. To thank someone who has helped you, click on the star icon below their name.
    - This way you will add him some reputation points ... thanks in advance.

  3. #3
    Registered User
    Join Date
    08-02-2012
    Location
    North Haven, CT
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Excel VBA: Find empty cells and Sum Cells before it

    Hey,

    Thanks for the link, that helped a ton.

+ 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