Magoosball
Board Regular
- Joined
- Jun 4, 2017
- Messages
- 70
- Office Version
- 365
I am trying to move an array based formula from a worksheet into a for loop in VBA.
I currently have a list of from dates in column A and to dates in column B. These dates represent where an employee lived during a period of time. I have a formula in column C that shows the dates if there is a gap of 30 days or more where the employee doesn't have a location where he / she lived. Here is the formula:
{=IF(C2=MAX(C$2:C$99),"",IF(SUMPRODUCT((C2+30>=B$2:B$99)*(C2< C$2:C$99))=0,"Gap: " & TEXT(C2,"MM/DD/YYYY") & " to " & TEXT(MIN(IF(B$2:B$99>C2,B$2:B$99)),"MM/DD/YYYY"),""))}
This formula works perfectly in Excel. I am trying to move this to VBA because my database reports multiple employees on the same spreadsheet separated by empty cells in column B and C. For example I will have the dates employee a lived from rows 2 to 12. B from rows 14 to 35 and so on. Of course these vary based off how many locations they have lived. Below is an example of what I am looking for the script to do:
[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]From Date
[/TD]
[TD]To Date[/TD]
[TD]Gaps[/TD]
[/TR]
[TR]
[TD]Employee 1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]04/01/2001[/TD]
[TD]10/01/2001
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]10/01/2001[/TD]
[TD]11/1/2001[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]12/1/2001[/TD]
[TD]03/01/2002[/TD]
[TD]Gap: 03/01/2002 to 02/12/2003[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]02/12/2003[/TD]
[TD]05/12/2005[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]03/18/2003[/TD]
[TD]01/01/2004[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]11/12/2004[/TD]
[TD]01/31/2005[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Employee 2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]02/01/2006[/TD]
[TD]05/01/2006[/TD]
[TD]Gap: 05/01/2006 to 06/26/2006[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]06/26/2006[/TD]
[TD]09/30/2006[/TD]
[TD]Gap: 09/30/2006 to 01/02/2007[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]01/02/2007[/TD]
[TD]03/16/2010[/TD]
[TD]Gap: 03/16/2010 to 05/03/2010[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]05/01/2007[/TD]
[TD]04/03/2008[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]07/01/2007[/TD]
[TD]02/22/2007[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]05/03/2010[/TD]
[TD]07/31/2010[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]08/20/2010[/TD]
[TD]05/30/2011
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]06/05/2011[/TD]
[TD]06/06/2015[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]06/28/2015[/TD]
[TD]11/20/2017[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Employee 3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]04/08/2013[/TD]
[TD]07/27/2013[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]08/20/2013[/TD]
[TD]11/24/2017[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Employee 4[/TD]
[TD]12/01/1995[/TD]
[TD]08/31/2001[/TD]
[TD]Gap: 08/31/2001 to 10/30/2001[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]10/30/2001[/TD]
[TD]07/17/2014[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]07/18/2014[/TD]
[TD]11/26/2017[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
So I will have to have one big loop referencing the last row in the worksheet and then a smaller loop stopping during blank cells.
Help is greatly appreciated! Thank you in advance!
I currently have a list of from dates in column A and to dates in column B. These dates represent where an employee lived during a period of time. I have a formula in column C that shows the dates if there is a gap of 30 days or more where the employee doesn't have a location where he / she lived. Here is the formula:
{=IF(C2=MAX(C$2:C$99),"",IF(SUMPRODUCT((C2+30>=B$2:B$99)*(C2< C$2:C$99))=0,"Gap: " & TEXT(C2,"MM/DD/YYYY") & " to " & TEXT(MIN(IF(B$2:B$99>C2,B$2:B$99)),"MM/DD/YYYY"),""))}
This formula works perfectly in Excel. I am trying to move this to VBA because my database reports multiple employees on the same spreadsheet separated by empty cells in column B and C. For example I will have the dates employee a lived from rows 2 to 12. B from rows 14 to 35 and so on. Of course these vary based off how many locations they have lived. Below is an example of what I am looking for the script to do:
[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]From Date
[/TD]
[TD]To Date[/TD]
[TD]Gaps[/TD]
[/TR]
[TR]
[TD]Employee 1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]04/01/2001[/TD]
[TD]10/01/2001
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]10/01/2001[/TD]
[TD]11/1/2001[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]12/1/2001[/TD]
[TD]03/01/2002[/TD]
[TD]Gap: 03/01/2002 to 02/12/2003[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]02/12/2003[/TD]
[TD]05/12/2005[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]03/18/2003[/TD]
[TD]01/01/2004[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]11/12/2004[/TD]
[TD]01/31/2005[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Employee 2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]02/01/2006[/TD]
[TD]05/01/2006[/TD]
[TD]Gap: 05/01/2006 to 06/26/2006[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]06/26/2006[/TD]
[TD]09/30/2006[/TD]
[TD]Gap: 09/30/2006 to 01/02/2007[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]01/02/2007[/TD]
[TD]03/16/2010[/TD]
[TD]Gap: 03/16/2010 to 05/03/2010[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]05/01/2007[/TD]
[TD]04/03/2008[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]07/01/2007[/TD]
[TD]02/22/2007[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]05/03/2010[/TD]
[TD]07/31/2010[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]08/20/2010[/TD]
[TD]05/30/2011
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]06/05/2011[/TD]
[TD]06/06/2015[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]06/28/2015[/TD]
[TD]11/20/2017[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Employee 3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]04/08/2013[/TD]
[TD]07/27/2013[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]08/20/2013[/TD]
[TD]11/24/2017[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Employee 4[/TD]
[TD]12/01/1995[/TD]
[TD]08/31/2001[/TD]
[TD]Gap: 08/31/2001 to 10/30/2001[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]10/30/2001[/TD]
[TD]07/17/2014[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]07/18/2014[/TD]
[TD]11/26/2017[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
So I will have to have one big loop referencing the last row in the worksheet and then a smaller loop stopping during blank cells.
Help is greatly appreciated! Thank you in advance!
Last edited by a moderator: