Consulting

Results 1 to 3 of 3

Thread: Filling Empty Cells with Data based on Averages

  1. #1
    VBAX Regular
    Joined
    Jan 2018
    Location
    Nova Scotia
    Posts
    83
    Location

    Filling Empty Cells with Data based on Averages

    Hi All,
    I'm looking for some help adding numbers to a very large data set. I have numbers in column C intermittently. I want to do the following:
    1.) If a number is in Column C, count the number of empty cells below it (but only up to the next number)...ie. C17,....C27 are empty cells, so the count would be 11
    2.) Divide this count (i.e. 11) by the number above the empty cells (i.e C16 = 9; therefore 9/11 = 0.818
    3.) Fill the empty cells below it with this average but only the empty cells (i.e. 0.818)
    4.) Continue with the next number to the end of the data set

    That's it. Sample data attached.

    Any help would be appreciated.
    Jim
    Attached Files Attached Files

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Something like this


    Option Explicit
    
    Sub Numbers()
    
        Dim rData As Range, rArea As Range, rAbove As Range
        Set rData = ActiveSheet.Cells(1, 1).CurrentRegion.Columns(3).SpecialCells(xlCellTypeBlanks)
        
        For Each rArea In rData.Areas
            With rArea
                Set rAbove = .Cells(1, 1).End(xlUp)
                rArea.Value = rAbove.Value / rArea.Cells.Count
            End With
        Next
    
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Regular
    Joined
    Jan 2018
    Location
    Nova Scotia
    Posts
    83
    Location
    Works Perfectly. Thank you Paul

Posting Permissions

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