A列和B列数据类型均为日期(mm/dd/yyyy),A类为任务下达日期,B列为任务完成日期。A列数据无空值,B列中可能存在有空值,若为空值则需替换该单元格为当前系统日期。
若B列-A列>=7,则A列该单元格背景色变为红色。
目前不太清楚怎么定义A列与B列的数据类型,以及怎样计算,请大神解答,十分感谢
请参考如下代码
sub mt7d()
dim a as range
dim b as range
dim d1 as date
dim d2 as date
dim daydiff as long
for i = 184 to 217
with sheet1
if .cells(i,12).value = "" then
.cells(i,12).value = Date
end if
d1 = .cells(i,10).value
d2 = .cells(i,12).value
daydiff = DateDiff("d",d1,d2)
if daydiff >= 7 then
.cells(i,10).Interior.ColorIndex = RGB (192,0,0)
end if
end with
next i