Question : Need Macro to Calcuate sum of highlighted cells in Excel

I am trying to write a macro that would display the sum of a group of highlighted cells.  For example, if I highlight 5 cells in a column or row, I could press control + E (to run the Macro) and a msgBox would pop up that tells me the sum.  Or, another example: I could also highlight a 3x7 range of cells and it would sum all 21 numbers, and again display this in a msgBox.  Nothing fancy - just quick and easy.

Can anyone help me with this?  I have two other attempts with the code but neither are working.  i can copy and paste if needed, but I could be quite off base with this.  Thanks in advance.

Answer : Need Macro to Calcuate sum of highlighted cells in Excel

Try this:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
Sub AddSelection()

    Dim cell As Range
    Dim SumValue As Long

    For Each cell In Selection
        SumValue = SumValue + cell.Value
    Next
    
    MsgBox "The sum of the selected values is: " & SumValue
    
End Sub
Random Solutions  
 
programming4us programming4us