简体   繁体   中英

Does Excel have a built-in “hypothetical” function?

I have an Excel cell with a complicated formula relating to many other cells.

Does a function exist that would allow me to look at what the value of that cell would be if I changed the value of another cell to a certain value?

Basically, I'm looking for the functionality of a simple data table in a function I can put directly in a cell. I can do this in VBA or by creating a data table, but I'm looking for a built-in method if one exists.

No.

As you have mentioned, you would be best served using a data table - there isn't an equivalent inbuilt function. The plus with data tables is that you can explicitly control their calculation

@brettdj's answer is correct. Unfortunately, I was wrong that I could do what I want even in VBA; the code below was what I was planning to write, but it does not work because functions called from a worksheet cannot change the worksheet:

Public Function Hypothetical(setthiscell As Range, tothisvalue As Variant, andobservethiscell As Range) As Variant
    Dim oldvalue As Variant
    oldvalue = setthiscell.Value
    setthiscell.Value = tothisvalue
    Dim result As Variant
    result = andobservethiscell.Value
    setthiscell.Value = oldvalue
    Hypothetical = result
End Function

Neither Scenarios or the Solver address my problem because I want to the solution to be automated. Apparently the only way to accomplish this task is to use data tables.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM