Inserted formula with cell reference does not recognize new input

守給你的承諾、 提交于 2020-08-10 19:24:49

问题


I swear this just worked yesterday...

I have a program that creates formulas within certain cells that depend on subsequent data entries into other cells:

Cells(i, 40).Formula = "= (N" & i & ")/AP" & i

So, APi can be input and/or changed after the fact, and the formula should give you the result for whatever value is there. However, I get a #Div/0! error no matter what value is in that cell. When I evaluate the formula (within Excel) and step through the calculations, it shows this (for one particular cell):

= (N64)/AP64 = (47.35)/AP64 = 47.35/AP64 = 47.35/9 = #DIV/0!

So, the formula recognizes that there is a value in the cell AP64, but then does not use it to properly calculate the result.

As I said at the top, this worked as I expected yesterday afternoon when I was testing it. Now that I need other people to start using it, of course, it doesn't. I changed nothing within the program relative to these lines of code.

I apologize if this is answered elsewhere - I really have no idea how to create a search for this type of problem.


回答1:


Two things to check:

1) Value of the cells used is formatted to a number (i've had #Value based on that a couple times) and

2) verify that modifying the code using fixed references provides the appropriate output ("A16" for some reason wasn't recognized as a cell reference in one I had show up). E.g., "$N" & i & "/$AP" & i


If those both look alright, you might try something like:

.Range(.Cells(3,40),.Cells(lr,40)).Formula = "=$N3/$AP3" 'ensure no random spaces

This should act like a fill-down in which the # 3 is iterated with the same row as the formula.



来源:https://stackoverflow.com/questions/51636878/inserted-formula-with-cell-reference-does-not-recognize-new-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!