View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Harald Staff Harald Staff is offline
external usenet poster
 
Posts: 292
Default Function or macro help

"Mark" skrev i melding
...
Find the sum of values in column D that equals the value
in A1
D
A1 10
600 100
500
50
200


=SUMIF(D1:D1000,A1)
this used in VBA:
MsgBox Application.WorksheetFunction.SumIf(Range(Cells(1, 4), Cells(1000,
4)), Cells(1, 1))

Is there a function that does this and can it tell me
which cells in Column D were used to find the Value in A1


I'd use a loop for that:

Private Sub CommandButton1_Click()
Dim R As Range, Cel As Range
Dim S As String
Set R = Range(Cells(1, 4), Cells(1000, 4))
For Each Cel In R
If Cel.Value = Cells(1, 1).Value Then _
S = S & Cel.Address(0, 0, xlA1) & ", "
Next
MsgBox S
End Sub

HTH. Best wishes Harald