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:
<tbody>
</tbody>
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:
From Date | To Date | Gaps | |
Employee 1 | |||
04/01/2001 | 10/01/2001 | ||
10/01/2001 | 11/1/2001 | ||
12/1/2001 | 03/01/2002 | Gap: 03/01/2002 to 02/12/2003 | |
02/12/2003 | 05/12/2005 | ||
03/18/2003 | 01/01/2004 | ||
11/12/2004 | 01/31/2005 | ||
Employee 2 | |||
02/01/2006 | 05/01/2006 | Gap: 05/01/2006 to 06/26/2006 | |
06/26/2006 | 09/30/2006 | Gap: 09/30/2006 to 01/02/2007 | |
01/02/2007 | 03/16/2010 | Gap: 03/16/2010 to 05/03/2010 | |
05/01/2007 | 04/03/2008 | ||
07/01/2007 | 02/22/2007 | ||
05/03/2010 | 07/31/2010 | ||
08/20/2010 | 05/30/2011 | ||
06/05/2011 | 06/06/2015 | ||
06/28/2015 | 11/20/2017 | ||
Employee 3 | |||
04/08/2013 | 07/27/2013 | ||
08/20/2013 | 11/24/2017 | ||
Employee 4 | 12/01/1995 | 08/31/2001 | Gap: 08/31/2001 to 10/30/2001 |
10/30/2001 | 07/17/2014 | ||
07/18/2014 | 11/26/2017 |
<tbody>
</tbody>
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: