Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel VBA: Formula is too complex for object

Tags:

button

excel

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.

This is the code I've written:

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.

like image 907
user2529177 Avatar asked Dec 06 '25 06:12

user2529177


1 Answers

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

like image 57
user2529177 Avatar answered Dec 08 '25 18:12

user2529177



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!