Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sam Sam is offline
external usenet poster
 
Posts: 699
Default Array computation in vba

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Array computation in vba


I wouldl use Sumproduct instead of SUM so yo don't have to worry about
an array formula. If would use Evaluate to get the results into VBA. I
used format to get the dates entered in the combobox in the same format
as the worksheet.

Results =
Evaluate("Sumproduct(($A:$A=StartDate)*($A:$A<=En dDate)*($B:$B=Employee))")

You need to use variable in the above method so do this

StartDate = combobox1.text
StartDate = format(DateValue(StartDate,"MM/DD/YY"))
EndDateDate = combobox2.text
EndDate = format(DateValue(EndDate,"MM/DD/YY"))
Employee = Combobox3.text

Results = Evaluate("Sumproduct(($A:$A=" & StartDate & ")*($A:$A<=" &
_
EndDate & ")*($B:$B=" & Employee & "))")


msgbox(Results)


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?u=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=195353

http://www.thecodecage.com/forumz

  #3   Report Post  
Posted to microsoft.public.excel.programming
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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Age computation owen.cxy Excel Programming 1 June 23rd 09 07:26 AM
percentage computation Excel Excel Discussion (Misc queries) 2 December 3rd 08 08:34 PM
Date Computation sylink[_3_] Excel Programming 1 November 20th 08 08:00 PM
computation error Rajneesh Arora Excel Discussion (Misc queries) 4 August 22nd 07 08:17 PM
Rew Macro For Computation Akash Excel Programming 8 February 27th 07 01:20 PM


All times are GMT +1. The time now is 12:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"