计算未来的服务date

我一直在研究一个从数据录入页面获取车辆服务和MOTdate的VBAmacros,将它们插入另一张表中的新行中,并在设定的间隔时间内计算将来的服务date。 这一切都很好,只是我有麻烦的下一个部分。 然后,我需要把这些date,并将其添加到一个时间表。

我试图设置嵌套的Do While循环,但我无法得到它的工作。 我已经做了一个简单的例子,我正在尝试做(下面的链接)。

红色是手动input的数据。 黄色是第一个macros产品,新行含有复制date,橙色计算的未来date。 绿色是插入的新行(我必须去的地方),但是我需要插入到新行中的符号。

在这里输入图像说明

这是我从数据库中input服务date的基本代码。

 x = 1 y = x + 1 z = 16 'my data starts in C6R16 and I have 5 dates (hence to 21) Do While z < 21 'Have a shedule for the whole year so 53. Do While x < 53 'If functions to locate which week the event is located If Worksheets("Dates Input").Cells(6, z).Value > Worksheets("Maintenance Shedule").Cells(3, x) Then If Worksheets("Dates Input").Cells(6, z).Value < Worksheets("Maintenance Shedule").Cells(3, y) Then 'Quick location of the lowest empy cell. The others will be full of data from prevous entries. Range("F9:F10").Select Do While Not IsEmpty(ActiveCell) ActiveCell.Offset(1, 0).Select Loop 'Move my active cell to the correct place ActiveCell.Offset(-1, (3 + x)).Select ActiveCell = "/" Else End If 'Move to the next set of dates in shedule x = x + 1 Loop 'move to next service date z = z + 1 Loop 

最重要的是,我需要添加(我假设)一个If语句来检查在同一周内是否有MOT(M)和service(/),以便一个不删除另一个。

任何指针和帮助将不胜感激。

x和z是一个计数器。 我会build议使用

 For x = 1 To 21 Next 

代替。 这似乎不是你的问题,但。

 Do While Not IsEmpty(~~~~~~) 

实际上意味着当单元格是空的时候。