You can use both worksheet functions or VBA to solve the problem.
First of all, let's see additional worksheet function solutions using array
functions techniques.
For example, if you got a list of numbers in A1:A20, and you got those "M"
in the adjacent column (B).
You can type the array formula:
=SUM(A1:A20*((B1:B20)="M"))
To input an array formula, after typing the formula, hold Ctrl+Shift then
press Enter.
Or, you can use the following "more clever" array formula:
=SUM(A1:A20*(OFFSET(A1:A20,,1)="M"))
Then, let's see the VBA solution.
With the cells in column A selected, run the macro below.
Sub example_macro()
Dim a As Range
Dim cell As Object
Dim answer
Set a = Selection 'can replace this with another range object description
For Each cell In a
If cell.Offset(0, 1).Value = "M" Then
answer = answer + cell.Value
End If
Next
MsgBox answer
End Sub
Regards,
Edwin Tam
(e-mail address removed)
http://www.vonixx.com