Vba - Summing Data Values

  • Re: Vba - Summing Data Values


    Depends.


    Are there any other cells with data in other than the data cells e.g. headings?


    If you just have a column of data which starts at row 5 and ends at row 12, or could start at row 7 and ends at row 14 etc. then it won't be a problem.


    If it's not like that however, then you'll need to supply some more information as to what you are trying to do and the surrounding environment.


    KJ

  • Re: Vba - Summing Data Values


    Hi, Thanks for your reply, I've got a table like this in excel, and I want to sum the number of new accounts in a separate column, so that when I enter a new value at the bottom of the table, the sum will change.


    Weeks No. of new accounts
    1 200
    2 250
    3 300
    4 200
    5 200
    6 300
    7 350
    8 200
    9 150
    10 300
    11 300
    12 250
    13 200

  • Re: Vba - Summing Data Values


    You should know where your VBA puts the data, beginning with whatever cell you deem as the first. If Cell A4 was the first cell, this would sum all the data below it:


    Code
    Sub ShowSumOfArea()
    Dim MyValue As Long
    ' select first cell of data area
    Range("A4").Select
    MyValue = WorksheetFunction.Sum(Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Value)
    MsgBox MyValue
    End Sub


    Quote from nuttytart1987

    How do I edit the VBA so that the 1st data cell is selected, and then the program calculates the sum of the data values, and then stop summing when I reach end of data?

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!