Excel VBA:公式对于对象而言过于复杂 [英] Excel VBA: Formula is too complex for object

查看:88
本文介绍了Excel VBA:公式对于对象而言过于复杂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个简单的问题,但令人非常沮丧.我在VBA中为电子表格编写了几个(相对简单的)宏,我希望这些电子表格非常人性化.

This may seem like a simple problem, but it's been very frustrating. I've written a couple (relatively simple) macros in VBA for a spreadsheet that I want to make very user-friendly.

换句话说,我希望所有宏都由按钮运行.但是,每当我尝试将按钮分配给宏时,都会出现错误:

In other words, I want all macros to be run by buttons. However, whenever I try to assign buttons to macros I am getting the error:

公式太复杂,无法分配给对象

Formula is too complex to be assigned to object

即使我尝试将其分配给一个空的子例程,也会发生这种情况.它有效,但仅适用于我编写的第一个宏.将其他子例程添加到模块后,就无法再为宏分配新按钮了.

This happens even when I try to assign it to an empty subroutine. It worked, but only for the first macro I wrote. Once I added other subroutines to the module, I could no longer assign new buttons to macros.

这是我编写的代码:

Sub Button1_Click()

selName = Range("C2").Value
div = Range("E2").Value
cost = Range("F2").Value
diff = div - cost

If diff < 0 Then
    diff = 0
End If
Range("G2").Select
ActiveCell.FormulaR1C1 = diff

x = Range("A2").Value + 1
Worksheets("VIP_TEMPLATE.PIVOT").Select
Range("J" & x).Select
ActiveCell.FormulaR1C1 = diff

Worksheets("CALCULATE").Select
Range("F2").Select
ActiveCell.ClearContents

End Sub

模块中还有另一个子例程,我认为这可能是导致该问题的原因?我想这是因为当我简单地将数据复制粘贴到新工作表中时,可以为例程分配一个按钮.我认为这与我的文件路径无关,因为我不使用任何(我认为)令人反感的字符.

I have another subroutine in the module, which I think may be contributing to the problem? I think this because when I simply copy-pasted my data into a new worksheet, I could assign a button to the routine. I don't think it has anything to do with my file path because I don't use any (I think) offending characters.

推荐答案

我发现了问题.事实证明,我的文件路径中确实有括号(埋在里面).

I have found the problem. It turns out that I did actually have brackets in my file path (buried way in there).

这篇关于Excel VBA:公式对于对象而言过于复杂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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