这里是答案编辑@Nick Peranzi回答适合我的请求后,我的问题,我不知道如何标记/提他,但是这是他的用户链接 https://stackoverflow.com/users/5472502/nick-peranzi
Sub FillCompletionDays()
Dim LLoop As Long
Dim LLRow As Long
Dim DateEnd As Date
Dim DateNext As Date
Dim DateNow As Date
LLoop = Range("A:A").Find(what:="Project name").Row + 1
LLRow = Range("A:A").Find(what:="*", searchdirection:=xlPrevious).Row
If LLRow <= LLoop Then Exit Sub
Do
'Only proceed if there is a valid date in column E
If Range("E" & LLoop).Value2 <> vbNullString Then
DateNow = DateSerial(Year(Range("E" & LLoop).Value2), Month(Range("E" & LLoop).Value2), _
Day(Range("E" & LLoop).Value2))
DateEnd = DateSerial(Year(Range("D" & LLoop).Value2), Month(Range("D" & LLoop).Value2), _
Day(Range("D" & LLoop).Value2))
'Check if another date is needed
If DateEnd > DateNow Then
'Check if next row is this project
If Range("A" & LLoop + 1).Value2 = Range("A" & LLoop).Value2 Then
'Check if a new date is needed
DateNext = DateSerial(Year(Range("E" & LLoop + 1).Value2), Month(Range("E" & LLoop + 1).Value2), _
Day(Range("E" & LLoop + 1).Value2))
If DateNext = DateNow Then
Else
If DateNext <> DateNow + 1 Then
'Insert a row
Rows(LLoop + 1).Insert shift:=xlShiftDown
Range("A" & LLoop + 1 & ":D" & LLoop + 1).Value2 = Range("A" & LLoop & ":D" & LLoop).Value2
Range("E" & LLoop + 1).Value2 = DateNow + 1
Range("B" & LLoop + 1 & ": E" & LLoop + 1).NumberFormat = "yyyy-mm-dd"
LLRow = LLRow + 1
End If
End If
Else
'Next row is another project; insert a row for this one
Rows(LLoop + 1).Insert shift:=xlShiftDown
Range("A" & LLoop + 1 & ":D" & LLoop + 1).Value2 = Range("A" & LLoop & ":D" & LLoop).Value2
Range("E" & LLoop + 1).Value2 = DateNow + 1
Range("B" & LLoop + 1 & ": E" & LLoop + 1).NumberFormat = "yyyy-mm-dd"
LLRow = LLRow + 1
End If
End If
End If
LLoop = LLoop + 1
Loop Until LLoop > LLRow
End Sub
考虑显示到目前为止你已经尝试过的东西,它会很长的路要走使它看起来就像你不能简单地要求其他人做你的工作,你...如果你*从字面上*不知道从哪里开始,请阅读“Do/While”和“ For/Next'循环。 –
@DavidZemens谢谢!我试图用excel公式来实现,但似乎没有一个简单的解决方案...我会给vba一个镜头...另外,我不要求任何人为我做我的工作,但我是把我的问题扔在那里,以防万一有人遇到类似的谜题,我会做剩下的事情,如果别人做了这些事情,我不必重新发明轮子...... – exlover
绝对无法完成公式,因为它们无法操纵表单/行。 –