Consulting

Results 1 to 3 of 3

Thread: Dividing a column by a range of numbers

  1. #1
    VBAX Newbie
    Joined
    Nov 2016
    Location
    Chicago
    Posts
    2
    Location

    Dividing a column by a range of numbers

    While (ActiveCell.Value > 0)
            While (ActiveCell.Value > 0)
                colTotal = colTotal + ActiveCell.Value
                ActiveCell.Offset(1, 0).Select
            Wend
            ActiveCell.Offset(1, 0).Value = colTotal
            avgSales = colTotal / Range("A" & Rows.Count).End(xlUp).Row
            colTotal = 0
            currentCol = currentCol + 1
            ActiveSheet.Cells(firstRow, currentCol).Select
        Wend



    I'm trying to compute average sales for each column, without using the average function itself. I correctly get each column total but I fail to get the colTotal to divide by the number in each column. Is there something I'm doing wrong here? The part I highlighted is the problem I believe. Is my count function wrong? Any help would be appreciated.

    Last edited by Aussiebear; 11-03-2016 at 06:55 PM. Reason: Added code tags

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    If A1 is the column title, then the row count would be at least one more than it should.

  3. #3
    VBAX Newbie
    Joined
    Nov 2016
    Location
    Chicago
    Posts
    2
    Location
    Thanks Kenneth! I managed to tweak it a bit and I got it working.

    Cheers

Posting Permissions

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