Consulting

Results 1 to 4 of 4

Thread: Sum of Cells Within the Selected Range (vba)

  1. #1

    Sum of Cells Within the Selected Range (vba)

    By vba code :


    How do I get the sum of cells within a selected range by pressing on the macro button , so that the result in cell A1 for example.



  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Why bother, you can see it in the statusbar, bottom right.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    xld is right it will serve you no purpose!, but, [VBA]Range("A1").Value = Application.WorksheetFunction.Sum(Selection)[/VBA]
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  4. #4
    Simon Lloyd ,
    thanks alot
    Because I need the result to be in the active cell changed the code to the following:
    [vba]
    ActiveCell.value= Application.WorksheetFunction.Sum(Selection)
    [/vba]


    the underlined was the part that i can't make it .

    so, again thank you very much.

Posting Permissions

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