Help me please

Help needed to fix spread sheet.

Problem:
Please see sheet attached; I wrote the following MS Excel (2010) syntax in cells D2:D11 to help me determine the "Earliest start date” (column D) in the range of each project ID number (column A):

=IF(C2="","",(SMALL($C$2:$C$11,1)))

How do I copy and paste the formula into the next groups of 10 cells for each project ensuring that the reference range is accurate? Any help with because if I copy and paste the absolute " $C$2:$C$11" will carry over, meaning that I will have to go and manually change the range, which is tedious for a large Excel sheet of about 500 projects (times 10 project teams = 5000 cells to manually enter).
A VBA "macros” code I guess will be ideal too.

Thank you in advance for your help.

Koby

AttachmentSize
Help needed.xlsx13.38 KB

Simpler formula provided?

Thank you Dave and Nick for your help and time. I don’t know if this might be of interest to members, I also got this help from another generous soul who told me to Just use the formula

=MIN(OFFSET($C$2,(INT((ROW(A2)+8)/10)-1)*10,0,10,1))

in C2, and copy down. It worked as-is, but I decided to prefix it with an IF statement to take care of empty date cells. So the resulting formula I pasted into C@ was

=IF(C2="","",(MIN(OFFSET($C$2,(INT((ROW(A2)+8)/10)-1)*10,0,10,1))))

Once again thanks, very much appreciated and keep up the good work.

Koby

Nick's picture

sort ur data by: 'Project ID

sort ur data by:

'Project ID number'
then
'Project start date' ascending..

then use vlookup on 'Project ID number' returning the 'Project start date' col..

no need to adjust the formula...

Alternatively, and a much better solution is to
- select all your data
- insert a pivot table
- choose 'Project ID number' as the row field
- choose Min Of 'Project start date' as the data field

then u get this:

Row Labels Min of Project start date
TX001 28-Aug-06
TX002 06-Oct-04
TX003 01-Mar-05
TX004 01-Jan-05
TX005 06-Oct-04
TX006 01-Jun-05
TX007 01-Mar-05
TX008 01-Mar-05
TX009 01-Jun-05
TX010 01-Apr-05

I'm guessing that using the

I'm guessing that using the subtotals tool in the spreadsheet isn't what you're after...?

Paste the following code into a UDF (To set up a UDF follow instructions here: http://www.wikihow.com/Create-a-User-Defined-Function-in-Microsoft-Excel)

Option Explicit

Public Function minDate()

Application.volatile

Dim startRow As Integer
Dim endRow As Integer
Dim caller_r As Integer
Dim r As Integer
Dim projID As String
Dim locDate As Date

caller_r = Application.Caller.Row
r = caller_r
projID = Cells(r, 1).Value
locDate = Cells(r, 3).Value
Do Until Cells(r, 1).Value <> projID
startRow = r
r = r - 1
Loop
r = caller_r
Do Until Cells(r, 1).Value <> projID
endRow = r
r = r + 1
Loop

For r = startRow To endRow
If DateDiff("d", locDate, Cells(r, 3).Value) <= 0 Then locDate = Cells(r, 3).Value
Next r

minDate = locDate

End Function

A couple of things you should be aware of.
1) This UDF does not take an input parameter. Just call it as "=minDate()" in your spreadsheet. It does assume, however, that your data is ordered as in your example, that the project titles are in column 1 and the dates in column 3.
2) I walk up and down from the row you call the function from to determine the "boundaries" of the project code, and then iterate from the minimum row to the maximum row to determine the lowest date. If there are "holes" in your first column, the rows will be bounded by those holes.
3) This will produce the date in whatever format your output column is set up to. If it is as "general" then you will get an Integer, so just make sure you reformat your cells to the date format that suits you.
4) Recalculating UDFs when inputs change is a bit of a dark art IMHO. This one should recalculate (note the application.volatile line), provided you have set calculation to automatic in excel.

Frankly, I would not use a UDF for this but rather write a macro that would do the same thing by walking the entire sheet, and that I could call by pressing a button. But that's probably because I have an unjustified aversion to UDFs and tend to do everything in macros anyway...

Hope this helps,

Dave

Re - Suggestion to use a macros instead of the UDF

Hi Dave,

Thank you for the help and suggestion to consider using a "macros" instead. I will like to take your suggestion, given that I am new to VBA/macros, I would very much appreciate it if you please help me with the macros code to cut and paste in the module. Thanks once again.

Koby