使用VBA将嵌套函数写入Excel

时间:2019-03-29 16:14:16

标签: excel vba excel-formula nested-function

我正在尝试使用VBA将以下嵌套公式写入单元格CY6

=IF(AND(CV6>MAX(BJ40,BJ5), CV6/MAX(BJ40,BJ5)>1.199999)," Moment Resistance Mr > Factored Moment Mf =" & ROUND(MAX(BJ40,BJ5),2)  & ". Mr/Mf =" & ROUND(CV6/MAX(BJ40,BJ5),2) & ". Proceed to Crack Control Step =>", " Moment Ratio Mr/Mf is Smaller than 1.2, Increase Steel Area. Mr/Mf=" & ROUND(CV6/BJ40,2))

我尝试使用的代码很简单

Range("CY6").value = " =IF(AND(CV6>MAX(BJ40,BJ5), CV6/MAX(BJ40,BJ5)>1.199999)," Moment Resistance Mr > Factored Moment Mf =" & ROUND(MAX(BJ40,BJ5),2)  & ". Mr/Mf =" & ROUND(CV6/MAX(BJ40,BJ5),2) & ". Proceed to Crack Control Step =>", " Moment Ratio Mr/Mf is Smaller than 1.2, Increase Steel Area. Mr/Mf=" & ROUND(CV6/BJ40,2)) "  

我也使用

尝试了同样的事情
worksheets("sheet1").range("CY6").formula= "...."

但是,它返回“预期的编译错误:语句结尾”并突出显示单词一下(第一个) 我认为这是因为使用了引号引起的,但是我不确定它应该如何工作。

1 个答案:

答案 0 :(得分:1)

让我们看看...

=IF(AND(CV6>MAX(BJ40,BJ5), CV6/MAX(BJ40,BJ5)>1.199999)," Moment Resistance Mr > Factored Moment Mf =" & ROUND(MAX(BJ40,BJ5),2) & ". Mr/Mf =" & ROUND(CV6/MAX(BJ40,BJ5),2) & ". Proceed to Crack Control Step =>", " Moment Ratio Mr/Mf is Smaller than 1.2, Increase Steel Area. Mr/Mf=" & ROUND(CV6/BJ40,2))

range("cy6").formula = "=IF(AND(CV6>MAX(BJ40,BJ5), CV6/MAX(BJ40,BJ5)>1.199999),"" Moment Resistance Mr > Factored Moment Mf ="" & ROUND(MAX(BJ40,BJ5),2) & "". Mr/Mf ="" & ROUND(CV6/MAX(BJ40,BJ5),2) & "". Proceed to Crack Control Step =>"", "" Moment Ratio Mr/Mf is Smaller than 1.2, Increase Steel Area. Mr/Mf="" & ROUND(CV6/BJ40,2))"