简体   繁体   English

将Excel公式单元格更改为VBA宏

[英]Change an excel formula cell into a vba macro

Please I need to change this formula: 请我需要更改此公式:

=IF(VAL.EMPTY(K15);"";MAX(K15-Today();0))

This formula gives the difference between two dates: 此公式给出两个日期之间的差额:

1) ie K15: 30/10/2017 1)即K15:30/10/2017

2) Today() 2)今天()

The maximum countdown stops at 0. 最大倒数计时将从0开始。

I need to transform this formula in a macro in order to insert this bit of code in a macro ran by Private Sub Worksheet_Change(ByVal Target As Range) . 我需要在宏中转换此公式,以便将这段代码插入由Private Sub Worksheet_Change(ByVal Target As Range)运行的宏中。

i hope the below code line should work, tested working fine for me. 我希望下面的代码行能够正常工作,经过测试对我来说很好。

 Sheet2.Range("M15:M38").Formula = "=IF(ISBLANK(K15),0,MAX(K15)-TODAY())"

too many arguments for IF function in your code. 您的代码中IF函数的参数过多。 also you may use 0 instead of "" to keep a simple string of formula. 您也可以使用0代替“”来保留简单的公式字符串。

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

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