• Status: Solved
• Priority: Medium
• Security: Public
• Views: 309

# Counting sales

Hi Experts - Counting purchases by month.

I'm finding it difficult to compose a routine to count how many of 6 specific items are being sold to our 25-40yr old customers . Here's the data:

Dim StockCode as string (5)
StockCode (1) = "721"
StockCode (2) = "725"
StockCode (3) = "2620"
StockCode (4) = "2517"
StockCode (5) = "723"
StockCode (6)  = "727"

25 -40yr old customers ( text file of  approx 300 index numbers )
eg
16433
15634
15555
etc

All sales records (text file of approx 3000 sales to ALL customers)  ie  0-99yr old
eg
customer nr    (tab)       date        (tab)  item description,
16433          (tab)  14/09/2007  (tab)          721

The output required is an excel report showing how many of each item were purchased by the  25-40yr old group (by month).

PURCHASES (25-40yr olds)   721's     725's     2620's    2517's     723's   727's
This month                                  16          72           8              25             2             1
Previous month                          14          63           5              .                .             .
-2 month                                       .
-3 month                                       .
etc
etc
till -23 months
0
peterdarazs
• 2
1 Solution

Commented:
Simply work through the final file with all the data of sales and put it into a pivot table
Row = Date / Month
Column = Item Description
TableData = Count of Date
0

Author Commented:
Pl remember i'm a beginner at programming, - I can define variables, compose  loops, but still have difficulty with:
1/ reading the text data into arrays
2/ counting the data in the different array fields
3/ presenting the results as an excel file.

Many thanks
Peter

0

Commented:
what version of VB?
I'm guessing 6, but, if you are using VB9 or .NET 3.5, you got lots better options...

assuming v6, first we'd need to break it down, and psuedo code out the steps, then put it into code.

so, lets tell the story first.

for each of the last 24 months, I want to know how many of each of these products I've sold to 25 to 40 year old customers.

so, first we create a collection of months

Dim months as Collection
set months = new Collection

Dim products as Collection

loop through and create a bunch of collections of collections
for i = 0 to -23 step -1
Set products = new Collection
etc...

next

so, now we have a collection of collections ready to store our data.

now we loop the file, line by line, see if the line
1. is one of our desired products
2. is in the date range
3. is for one of our target customers

if it is, we will have a place for it in our collections, we just add one to it

if it is, all you need to do is increment the proper item by adding one to it.

months(month)(product) = months(month)(product) + 1

or what it might look like with values rather than variables

months("-22")("721") = months("-22")("721") + 1

then, once we've looped all these records, we just loop the collection to output the data.

open excel application object in code, and write out the data....

for i = 0 to -23 step -1

sheet1.cells(...) = months(i)("721")
sheet1.cells(...) = months(i)("725")
....

next
0

Author Commented:
Ok - that makes sense and I'll try put it into action. Many thanks and good luck.
Peter
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.