Excel Visual Basic 1004错误,对象“范围"的方法“值"失败 [英] Excel visual basic 1004 error, method 'value' of object 'range' failed

查看:81
本文介绍了Excel Visual Basic 1004错误,对象“范围"的方法“值"失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为excel添加了一些插件.但是由于某种原因,它失败了.全新启动excel后,它可以正常工作,但是当我将粘贴文本复制到excel中并尝试运行它时,出现了以下错误:运行时'1004',对象'range'的方法'Value'失败.

我想做的事情很简单.我喜欢在不使用公式=的情况下构建公式:(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()
Do
ActiveCell.Value = "=" & ActiveCell.Value
ActiveCell.Offset(1, 0).Select
Loop While ActiveCell.Value <> Empty
end 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 String
Do
    Temp = ActiveCell.Value2
    Temp = Replace(Temp, ",", ".", 1)
    ActiveCell.Formula = "=" & Temp
    ActiveCell.Offset(1, 0).Select
Loop While ActiveCell.Value2 <> Empty
End Sub

Thanks for all your suggestions.

这篇关于Excel Visual Basic 1004错误,对象“范围"的方法“值"失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆