【问题标题】:Write Nested Function Into Excel Using VBA使用 VBA 将嵌套函数写入 Excel
【发布时间】:2019-03-29 16:14:15
【问题描述】:

我正在尝试使用 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= "...."

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

【问题讨论】:

  • 要添加 cmets 和排序,您需要在 info 之间使用 & 符号,例如:range("cy6").formula = "=if(cond=cond,1,0)" & "字”;对于其他嵌入的单词,您需要打开/关闭引号,例如 "=if(cond=cond,""True"",""False"")"
  • (1) 将字符串中的所有引号字符加倍,以便 VBA 编译器知道您需要引号字符而不是结束字符串。 (2) 用户 Range("CY6").formula 分配公式,而不是 .value

标签: excel vba excel-formula nested-function


【解决方案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))"

【讨论】:

  • 天啊,你们真快!我以为我明天必须回来,但没有 10 分钟。非常非常感谢!
  • @MohamedR 这对你有用吗?如果是这样,请标记为已回答(帖子左侧的复选标记),以便在搜索中适当标记
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-10
  • 1970-01-01
  • 2016-10-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多