jeudi 27 juin 2019

Setting an If Statement based on the second entry of an ID

This is a continuation of a question I asked earlier today. Got the answer to the initial question by a @ScottCraner however I am now required to make a second version.

So basically I have an excel sheet featuring a number of different id's, dates, and a column where I would like to specify beginning middle or end in a 3rd column depending on the SECOND DATE in the ID. However this should only apply to the block of the same ID. When the next ID passes through, the date of the first ID in the block will determine the rest of the 3rd column, and so on and so forth.

The issue is much better understood when looking at the dataset.

ID      DATE      formula_col
10R46   10/8/2011
10R46   2/18/2012
10R46   6/30/2012
10R47   2/4/2010
10R47   5/16/2010
10R47   8/8/2010
10R47   12/11/2010
10R47   1/4/2011
10R48   6/26/2011
10R48   9/11/2011
10R48   1/29/2012
10R48   4/20/2012
10R48   7/8/2012

So the formula_col column should be filled based on the SECOND DATE in the ID. Both the first and second will be "Beginning" and the third would follow the pattern:

The date in the second row of the same ID first month is beginning, next is middle, next is end, then it repeats.

So if the first month was February (2) (found in the second date of the ID block), then the formulas for these ID's would be: February: Beginning March: Middle April: End May: Beginning June Middle July: End August: Beginning September: Middle October: End November: Beginning December: Middle January: End And any could appear, not necessarily beginning, middle, end in that order. But they will always be in date order, no going back in time and such until the ID is over.

ID      DATE      formula_col
10R46   10/8/2011 Beginning
10R46   2/18/2012 Middle
10R46   6/30/2012 Beginning
10R47   2/4/2010  Beginning
10R47   5/16/2010 Beginning
10R47   8/8/2010  Middle
10R47   12/1/2010 End
10R47   1/4/2011  Beginning
10R48   6/26/2011 Beginning
10R48   9/11/2011 Beginning
10R48   1/29/2012 End
10R48   4/20/2012 End
10R48   7/8/2012  End

The code to do this based on the first ID (provided by @ScottCraner)

==CHOOSE(MONTH(B2)-MONTH(INDEX(B:B,MATCH(A2,A:A,0))),3)+1,"Beginning","Middle","End"))

This is great, but I would like to check on the second ID that appears. Something tells me VBA is required to do this.

I'm not sure if this is helpful but the first ID has a value next to it in a completely seperate column and the date ID column which sets the whole block in motion would follow below it.

ID      DATE      formula_col  extra
10R46   10/8/2011 Beginning    504444.27
10R46   2/18/2012 Middle   
10R46   6/30/2012 Beginning
10R47   2/4/2010  Beginning    1022.22
10R47   5/16/2010 Beginning
10R47   8/8/2010  Middle
10R47   12/1/2010 End
10R47   1/4/2011  Beginning
10R48   6/26/2011 Beginning    239.33
10R48   9/11/2011 Beginning
10R48   1/29/2012 End
10R48   4/20/2012 End
10R48   7/8/2012  End

So the months would be determined by the second date in the ID block, or in other words the row below a cell with values in "extra"

Aucun commentaire:

Enregistrer un commentaire