Specific list of Customers in Sheet1
Invoices list in Sheet2 [Of course with more than one invoice per
Customer]
How do I loop thru Sheet1, retrieve pertaining data in Sheet2 and
write it in Sheet3.
Classic and simple but I need a refresher and my browsing of this
group has not
produced the desired result yet.
What will change in the code, if any, if the 2 lists are not sorted by
Customer ?
Thank you for your help
Here is some general pseudo-code ... if you need help with any of it,
post again!
'First, get list of customers
sheets("sheet1").activate 'or better yet, change the sheet name in
VBE, so it's just Sheet1.Activate
cells(1,1).select
do until activecell=""
for icounter = 1 to inumcustomers
if strCustomer(icounter)=activecell then
AAAH! Hit Send too early!
Option Explicit
Private Sub OneTwoThree()
'declarations
Dim bnDup As Boolean
Dim iCounter As Integer
Dim iNumCustomers As Integer
Dim strCustomers() As String
Dim varValue As Variant
Dim varValueSum() As Variant
Dim strCustomersActive As String
'First, get list of unique customers
Sheet1.Activate
Cells(1, 1).Select
Do Until ActiveCell = ""
bnDup = False
For iCounter = 1 To iNumCustomers
If strCustomers(iCounter) = ActiveCell Then
bnDup = True
End If
Next iCounter
If bnDup = False Then
iNumCustomers = iNumCustomers + 1
ReDim Preserve strCustomers(iNumCustomers)
strCustomers(iNumCustomers) = ActiveCell
End If
ActiveCell.Offset(1, 0).Select
Loop
'Next, get required data from sheet 2 .... say we just need to sum
values in column B for customers in column A
Sheet2.Activate
Cells(1, 1).Select
ReDim varValueSum(iNumCustomers)
Do Until ActiveCell = ""
strCustomersActive = ActiveCell
varValue = ActiveCell.Offset(0, 1).Value
For iCounter = 1 To iNumCustomers
If strCustomersActive = strCustomers(iCounter) Then
varValueSum(iCounter) = varValueSum(iCounter) +
varValue
End If
Next iCounter
ActiveCell.Offset(1, 0).Select
Loop
'Go to sheet 3 and print
Sheet3.Activate
Cells(1, 1).Select
For iCounter = 1 To iNumCustomers
ActiveCell = strCustomers(iCounter)
ActiveCell.Offset(0, 1) = varValueSum(iCounter)
ActiveCell.Offset(1, 0).Select
Next iCounter
End Sub