我有一个数据表“订单”,其中包含格式的数据
order no Customer Sales Executive Order Status Order Date
211 nokia john cancelled 23-May-13
643 panasonic andrew fulfilled 23-May-13
209 samsung john fulfilled 4-Apr-14
453 philips andrew fulfilled 4-Apr-14
311 dell mary fulfilled 16-Apr-14
865 panasonic andrew fulfilled 16-Apr-14
201 apple john fulfilled 3-May-14
453 hp mary cancelled 3-May-14
205 nokia john fulfilled 4-May-14
643 philips andrew fulfilled 4-May-14
312 lenovo mary fulfilled 22-May-14
204 apple john fulfilled 7-Jun-14
432 hp mary fulfilled 7-Jun-14
214 nokia john pending 25-Jun-14
754 panasonic andrew fulfilled 25-Jun-14
以上是订单表中众多列中重要的列。
我有另一个工作表,其中列出了“销售主管”,并想知道他们按月完成了多少个独特客户的订单
Sales Executive Apr-14 May-14 Jun-14
john <value> <value> <value>
mary <value> <value> <value>
andrew <value> <value> <value>
我想编写代码以读取行中的销售主管姓名和列中的月份,然后给出如下答案
Sales Executive Apr-14 May-14 Jun-14
john 1 2 1
andrew 2 2 1
mary 1 1 1
我正在寻找可以按月运行的 vba 代码。上面的示例是实际数据的样本集。
我对 VBA 比较陌生,需要代码方面的帮助。
如果我得到关于代码如何工作的解释会很有帮助,因为我需要类似的代码来查找每个销售主管在几个月内产生了多少产品和总收入。
提前感谢您的帮助
编辑(来自下面的 OP 评论的代码):
Sub UniqueReport()
Dim dict As Object
Set dict = CreateObject("scripting.dictionary")
Dim varray As Variant, element As Variant
Dim lastrow As Long
lastrow = Sheets("Orders").Range("N" & Rows.Count).End(xlUp).Row varray = Sheets("Orders").Range("N2:N" & lastrow).Value
For Each element In varray
If dict.exists(element) Then
dict.Item(element) = dict.Item(element) + 1
Else
dict.Add element, 1
End If
Next
ActiveSheet.Range("P2").Value = dict.Count
End Sub