[英]excel vba formula with date compare in IF function within a formula
Let's say cell A1 is a Date: 23/06/2017 假设单元格A1是日期:2017年6月23日
Now in excel if I put the following formula in cell B1: 现在在excel中,如果我将以下公式放在单元格B1中:
= IF(INT(C2)>INT(2/15/2017);"Year1";"Year2")
then it's working fine. 然后就可以了
However, If I try to put it thought VBA coda as:- 但是,如果我尝试将其认为VBA尾声为:-
Set sht1 = xWb.Sheets("ProcessedData")
sht1.Range("B1").Select
sht1.Range("B1").Formula = _
"=IF(INT(A1)>INT(2/15/2017);""Year1"";""Year2"")"
It is giving me error 1004 (Object not found). 它给我错误1004(找不到对象)。 I tried with CDate but I think, I am missing something here. 我尝试过CDate,但我认为这里缺少一些东西。
Can you please help me with this issue. 您能帮我解决这个问题吗?
Excel is English oriented , you are using ;
Excel是面向英语的 ,您正在使用;
in your formula. 在您的公式中。
So either change your ;
所以要么改变你;
to ,
inside your formula string, like: 对,
你的公式字符串中,如:
sht2.Range("B1").Formula = "=IF(INT(A1)>INT(2/15/2017),""Year1"",""Year2"")"
Or, change Formula
to FormulaLocal
as in the following line: 或者,如下行将Formula
更改为FormulaLocal
:
sht2.Range("B1").FormulaLocal = "=IF(INT(A1)>INT(2/15/2017);""Year1"";""Year2"")"
Note : in the Formula
line I think you meant to use sht1
and not sht2
, so it should be: 注意 :在Formula
行中,我认为您打算使用sht1
而不是sht2
,因此应该是:
sht1.Range("B1").Formula = "=IF(INT(A1)>INT(2/15/2017),""Year1"",""Year2"")"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.