The listbox which will not save has an input from another listbox and I'm assuming that this is where the problem is arising. |
Sort of. You have several problems.
First, notice that block of code that looks at the variable "OnLoad"? That is incredibly important. At the top of the script there should be a line that says "Dim OnLoad : OnLoad=1". That declaration and assignment are only executed when the worksheet is loaded, or when you exit the script editor. So the block of code looks at the value of OnLoad, and if it's 1 (i.e the worksheet was just loaded) then it sets the cursor selection to Inputs(0).Value, and sets OnLoad equal to 0. By deleting the first line you stop that block of code from ever executing. Further, it looks at Inputs(0).Value, but you have moved the SaveData statement to input 1, so even if it did execute it can't set the selection to the saved value.
The next problem is what you are doing with If Geo<>save. When you first load the worksheet save is a null, because it has never been assigned to anything. I assume what you are trying to do is check whether the input has changed, but it's not quite that simple. When the worksheet is first loaded the input must be the same as when it was saved (because you saved the state of the other listbox), so you need to trap that special case: OnLoad again!
I very recently uploaded new versions of the "Saving the state of controls" worksheets: Saving the state of controls.zip I assume you haven't seen them, because I included listboxes that set the list based on an input. They are not quite what you want, but they are close enough that I think you can figure it out. In those examples, if the list is changed the selection is cleared. If that's not what you want then in the "Extra Components" worksheet: Extra Components.mcd there is another example of a dynamically filled listbox that, if possible, retains the selection.