View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Bernard Liengme Bernard Liengme is offline
external usenet poster
 
Posts: 4,393
Default Need help with formula

Hello:
Here is a VBA solution. If necessary, see David McRitchie's site on "getting
started" with VBA
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Function myTotal(myWhat)
Application.Volatile
myLast = Cells(Rows.Count, "A").End(xlUp).Row
myTotal = 0
MyCount = 0
For j = myLast To 1 Step -1
If Cells(j, "A").Value = myWhat Then
myTotal = myTotal + Cells(j, "B").Value
MyCount = MyCount + 1
End If
If MyCount = 2 Then Exit For
Next j
If MyCount < 2 Then myTotal = myTotal & " (found " & MyCount & ")"
End Function

best wishes
--
Bernard V Liengme
www.stfx.ca/people/bliengme
remove caps from email

wrote in message
ups.com...
Suppose you have 2 columns of data. Data gets added to the columns
frequently.

A B
xyz 4
abc 3
jkl 5
xyz 2
abc 1
def 4
abc 3

I need to calculate the total number in column B for the last 2
entries. Thus, if looking for "abc", the answer would be 4 (3+1),
since the abc got a 3 the last entry and 1 for the previous entry.
Using the same formula for xyz would return 6 (2 +4).

Any ideas on how I can accomplish this?