Date client stoped activity

cocks17

New Member
Joined
Dec 20, 2010
Messages
36
Hi Board

My challenge is in the screenshot below. Its a typical data set from what I work with. I need to populate the 2 tables with a list of clients which have stopped activity last month and this month with the date they stopped and the revenue they generated for that month.

The rule to say a client has stopped in current month is no activity in a the most recent date of data available or earlier. The data is not always today so would need to be based on the most recent date along the top row.

The rule needed for the last month to say someone has stopped is logical meaning they either stopped mid month or did not continue to the current month.


excelexample.jpg


any and all suggestions welcome!

Thanks
Paul
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Let's give this a swing;
Excel Workbook
BCDEFGHIJKLMNOPQRST
26/27/20116/28/20116/29/20116/30/20117/1/20117/2/20117/3/20117/4/20117/5/20117/6/2011Client Stopped Last MonthDate StoppedRevenueClient Stopped This MonthDate StoppedRevenue
3Client 1315403405498Client 16/30/2011$498.00Client 27/6/2011$580.31
4Client 2164.96189.704218.1596250.88354288.5161331.7935381.5625438.7969504.6164580.3089Client 37/3/2011$1,001.49
5Client 3432.97497.9155572.602825658.4932488757.2672870.85731001.486
Sheet


The code goes in a module.
MakeReport is the primary procedure to run.
You can use the variables to adjust as needed.

Code:
Option Base 0
Type ClientRec
    ClientName As String * 20
    StopDate As Date
    Revenue As Currency
    CurrOrLast As String
End Type
Dim arr() As ClientRec
 
Sub MakeReport()
DateRow = 2
FirstCol = 3
LastCol = 12
LastRow = Range("B" & Rows.Count).End(xlUp).Row
arrIdx = 0
ReDim arr(LastRow - (DateRow + 1))
For RowIdx = (DateRow + 1) To LastRow
    arr(arrIdx).ClientName = Cells(RowIdx, 2)
    For ColIdx = LastCol To FirstCol Step -1
    Cells(RowIdx, ColIdx).Select
        If Cells(RowIdx, ColIdx) > 0 Then
            arr(arrIdx).StopDate = CDate(Cells(DateRow, ColIdx))
            arr(arrIdx).Revenue = Cells(RowIdx, ColIdx)
            If Month(arr(arrIdx).StopDate) = Month(Cells(DateRow, LastCol)) Then
                arr(arrIdx).CurrOrLast = "C"
            Else
                arr(arrIdx).CurrOrLast = "L"
            End If
            arrIdx = arrIdx + 1
            Exit For
        End If
    Next ColIdx
Next RowIdx
For arrIdx = LBound(arr) To UBound(arr)
    Debug.Print arrIdx, arr(arrIdx).ClientName, arr(arrIdx).StopDate _
    ; arr(arrIdx).Revenue, arr(arrIdx).CurrOrLast
Next
DumpArray "N3", "R3"
End Sub
Sub DumpArray(LastMonth$, ThisMonth$)
Dim StartCell As Range
Set StartCell = Range(LastMonth)
vSwitch = "L"
 
For l0 = 1 To 2
RoSet = 0: CoSet = 0
    If l0 = 2 Then
        vSwitch = "C"
        Set StartCell = Range(ThisMonth)
    End If
    For arrIdx = LBound(arr) To UBound(arr)
        If arr(arrIdx).CurrOrLast = vSwitch Then
        StartCell.Offset(RoSet, CoSet).Select
            StartCell.Offset(RoSet, CoSet) = arr(arrIdx).ClientName: CoSet = CoSet + 1
            StartCell.Offset(RoSet, CoSet) = arr(arrIdx).StopDate: CoSet = CoSet + 1
            StartCell.Offset(RoSet, CoSet) = arr(arrIdx).Revenue: CoSet = CoSet + 1
            RoSet = RoSet + 1: CoSet = 0
        End If 'C or L
    Next arrIdx
Next l0
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,676
Members
452,937
Latest member
Bhg1984

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top