我想做的事情很简单.我喜欢在不使用公式=的情况下构建公式:(B5 + B6)/2,因此Excel不会计算这些表达式.我最后得到一个大列,完成后,我想选择要计算的列的第一个单元格,激活我的加载项,然后他在前面放一个'='并向下循环直到一个空单元格.这样,现在就可以计算出我列中的每个单元格.我迷路了,你能帮我吗? Sub makeFormula()做ActiveCell.Value ="="&ActiveCell.ValueActiveCell.Offset(1,0).选择ActiveCell.Value<>时循环空的结束子 解决方案我找到了解决方案,并通过调试发现了逗号是问题所在,因此我将逗号更改为点,然后进行计算.现在它就像一种魅力. Sub makeFormula()昏暗的温度作为字符串做温度= ActiveCell.Value2Temp =替换(Temp,,",.",1)ActiveCell.Formula ="="&温度ActiveCell.Offset(1,0).选择ActiveCell.Value2<>时循环空的结束子 感谢您的所有建议.I made a little add-in for excel.But for some reason it fails. After a fresh startup of excel it works fine, however when I copy paste text into excel and try to run it, it gives me the error: run-time '1004' , method 'Value' of object 'range' failed.What I'm trying to do, is quit simple. I like building formula's like : (B5+B6)/2 without the use of an '=' in front so Excel doesn't calculate these expressions. I end up with one big column, and after I am finished I would like to select the first cell of the column with calculations, activate my add-in and he puts an '=' in front and loops downward untill an empty cell. This way each cell in my column is now calculated.I am lost, can you help me ?Sub makeFormula()DoActiveCell.Value = "=" & ActiveCell.ValueActiveCell.Offset(1, 0).SelectLoop While ActiveCell.Value <> Emptyend Sub 解决方案 I've found the solution, with debugging I found out that commas are the problem, So I change the comma to a dot, and then calculate. And now it works like a charm.Sub makeFormula()Dim Temp As StringDo Temp = ActiveCell.Value2 Temp = Replace(Temp, ",", ".", 1) ActiveCell.Formula = "=" & Temp ActiveCell.Offset(1, 0).SelectLoop While ActiveCell.Value2 <> EmptyEnd SubThanks for all your suggestions. 这篇关于Excel Visual Basic 1004错误,对象“范围"的方法“值"失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 05:21