View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Array computation in vba

Assuming your controls have default names and that you are using a
CommandButton's Click event to execute your code, give this code a try...

Private Sub CommandButton1_Click()
Dim X As Long, LastRow As Long, Transactions As Double
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For X = 1 To LastRow
With Worksheets("Sheet1")
If .Cells(X, "A").Value = CDate(ComboBox1.Value) And _
.Cells(X, "A").Value <= CDate(ComboBox2.Value) And _
.Cells(X, "B").Value = ComboBox3.Value Then
Transactions = Transactions + 1
End If
End With
Next
Label1.Caption = Transactions
End Sub

--
Rick (MVP - Excel)



"Sam" wrote in message
...
I have a data table that has dates in column A and names in column B. If I
wanted to determine how many transactions an employee completed within a
given period, I'd use an array formula:
"=Sum(($A:$A=StartDate)*($A:$A<=EndDate)*($B:$B=E mployee)).

However I want to have a userform with a combo box for start date, another
for end date, another for employee. Then I want a label to display the
number
of transactions the same as the Excel formula above. How can I code vba to
compute this?

Thanks,

Sam