VBA将嵌套的if条件分配给某些范围单元格

时间:2017-10-18 10:25:48

标签: excel vba

我需要VBA代码才能将以下公式分配到范围G4:G1000,

通过比较其他列和当前日期,请帮助我。

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以使用此功能,您可能需要根据需要修改wb和ws。

Sub mysub()
Dim wb As Workbook
Dim ws As Worksheet
Set wb As ActiveWorkbook
Set ws As wb.Sheets("Sheet1")
ws.Range("G4:G1000").Formula = "=IF(A4="Ended OK","Completed",IF(A4="Executing","In progress",IF(D4=1,ROUND(((NOW()-1)-(B4+E4))*24,0),ROUND(((NO‌​W())-(B4+E4))*24,0))‌​))"
End Sub