形式のデータを含むデータシート「注文」があります
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