简体   繁体   English

计算未来的服务日期

[英]Calculate future service dates

I have been working on a VBA Macro that takes vehicle service and MOT dates from a data entry page inserts them into a new line on a different sheet and calculates future service dates on a set interval time I have entered. 我一直在研究VBA宏,该宏从数据输入页面获取车辆维修和MOT日期,将它们插入到另一张纸上的新行中,并在我输入的设定间隔时间内计算将来的维修日期。 This all works fine its just the next part I am having trouble with. 这一切都很好,这只是我遇到的下一部分。 I then need to take these dates and add them into a schedule. 然后,我需要考虑这些日期并将其添加到日程表中。

I have tried setting up nested Do While loops but I can't get it working. 我尝试设置嵌套的Do While循环,但无法正常工作。 I've made a simplified example of what I am trying to do (link below). 我已经做了一个简化的示例,说明了我要做什么(下面的链接)。

Red is the manually entered data. 红色是手动输入的数据。 Yellow is the 1st macro product with the new line containing copied dates with orange calculated future dates. 黄色是第一个带有新行的宏产品,该行包含复制的日期和橙色的计算出的将来日期。 Green is the new line inserted (where I have got to) but I need the symbols inserted into that new row. 绿色是插入的新行(我必须到达的位置),但是我需要在新行中插入符号。

在此处输入图片说明

This is the basic code I have have for entering the service dates into the schedule from the database. 这是我从数据库中将服务日期输入到计划中的基本代码。

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

On top of this, I need to add (I assume) an If statement to check if there is an MOT (M) and service (/) in the same week so that one does not delete the other. 最重要的是,我需要添加(假设) If语句来检查同一周是否存在MOT(M)和服务(/),以便一个不会删除另一个。

Any pointers and help would be greatly appreciated. 任何指针和帮助将不胜感激。

x and z are counters by one. x和z为1的计数器。 I would recommend using 我建议使用

For x = 1 To 21
Next

instead. 代替。 This doesn't seem to be your problem though. 不过,这似乎不是您的问题。 The

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

actually means do while the cells are empty. 实际上是指在单元格为空时执行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM