Reputation: 71
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.
Upvotes: 3
Views: 14639
Reputation: 71
I have found the problem. It turns out that I did actually have brackets in my file path (buried way in there).
Upvotes: 1