The refedit control is absolutely awful. Here are some rules using the contol
1. Cannot use on a modeless form - if you do it will most likely crash excel. Userforms are modal by default so unless you have set it to modeless then this should not be a problem
2. Only use refedit control on userforms - do not place them inside frames or anything else (multipage forms) - use on a single form only
3. As a general statement you may as well forget about ALL of the refedit events - they basically DO NOT WORK - if you try placing code inside a refedit event then weird things can happen - usually the form will just unload. For example try this. Place 2 refedit controls on a form and add this code to the form
When you exit the refedit1 control and go to the second one all that will happen is that the value from the refedit1 control will show in a message box however the worksheet will not be selected. (Remember that the refedit value is a string and NOT a range) - If you then click back into the refedit1 control then the form will probably just unload. If you try the following again just with 2 refedit controls
When you exit the first refedit control most likely NOTHING will happen and the form will just unload.
The point is that refedit events are very very unreliable and should be avoided. Essentially all refedit controls are good for is getting the refedit.value and that is about it.
It has also been suggested that you should remove the reference to the refedit control (In the VB editor select tools and then references then untick refedit - to me it seems to make no difference.
So what do you do - I have attached a sample workbook with 3 refedit controls and a command button and have used the following code on the form
What this will do is that every time you place a value into the refedit control you push the command button and the region you just selected will stay active - if you don't code for the refedit value as you said in your post the form will just appear on whatever sheet was active at the time the form was loaded. By passing the refedit value (which is a string) and the control to a separate sub it is easier to use multiple refedit controls - you will just have to add some more conditional statements to the command_button sub. This way each refedit control is not visible until the previous refedit control is filled.
The refedit control is a pain to work with - its events are pointless. I hope the above code can be adapted to your particular situation.
Bookmarks