pyscripter / XLRisk

Excell addin for performing Monte Carlo simulation
MIT License
112 stars 24 forks source link

Tornado chart not showing #11

Closed Eberwijn closed 9 months ago

Eberwijn commented 11 months ago

Book1.xlsx Goodday,

I realy like the plug in, it works realy fast and provides a usefull outcome However im struggeling to get a tornado chart reported.

it seems to struggle with the onedrive integration? image

can you help out on this topic? many thanks!

Hans

pyscripter commented 11 months ago

Here it works well: image

Are you using the latest version of XLRisk? Are you using a recent version of Excel?

Eberwijn commented 11 months ago

Hello,

Im using the latest office 365 excel version, and the latest version from github. I think its a local issue on my own IT environment, so sorry for the issue i raised.

I really appreciate the tool you have created!

Kind regards Hans Eberwijn

joktimo commented 9 months ago

Hi,

I've been having this same issue, and I think I have solved it.

The problem is in Sub ProduceTornadoDiagram() and it only arises if the user has Excel localized to some other language than English. What makes this even more complicated is that, if ProduceTornadoDiagram is excuted in break mode step by step, the code works perfectly well (at least sometimes)...

These two lines seems to be the problem: mOutSheet.Names.Add Name:="TornadoX", RefersTo:="=INDIRECT(" & Cell.Offset(5).Value & Cell.Offset(6).Address() & ")" mOutSheet.Names.Add Name:="TornadoY", RefersTo:="=OFFSET(INDIRECT(" & Cell.Offset(5).Value & Cell.Offset(6).Address() & "),0," & Cell.Offset(5).Value & Cell.Offset(2).Address & ")"

For some reason Excel doesn't localize these formulas to the formula notation of the local language before writing them down as named ranges, which will result in error in the next line of the code ( mOutSheet.Range("TornadoY").Select )

This can be seen from the screenshot I took (TornadoX and TornadoY in Risk results 1 are incorrect, Risk results 2 is after the correction): kuva

This can be fixed, for example, by writing the formulas to cells and then reading them back with .FormulaLocal

So for example by changing the previous bit of code like this: Cell.Offset(7).Formula = "=INDIRECT(" & Cell.Offset(5).Value & Cell.Offset(6).Address() & ")" Cell.Offset(8).Formula = "=OFFSET(INDIRECT(" & Cell.Offset(5).Value & Cell.Offset(6).Address() & "),0," & Cell.Offset(5).Value & Cell.Offset(2).Address & ")"

mOutSheet.Names.Add Name:="TornadoX", RefersTo:=Cell.Offset(7).FormulaLocal mOutSheet.Names.Add Name:="TornadoY", RefersTo:=Cell.Offset(8).FormulaLocal

pyscripter commented 9 months ago

Thanks! I was not aware of the localization of function names. I have also found this: https://stackoverflow.com/questions/13247771/excel-macro-inserting-internationally-valid-formula-during-run-time