View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Paul Paul is offline
external usenet poster
 
Posts: 661
Default RefEdit Exit not firing

I've tried using your code 'as is', but get exactly the same result.

I've been using the control to select a range on the screen rather than
entering text, so there's little chace that the text in the control is
invalid as a range.

Even placing a breakpoint on the very first line is either ignored or the
failure occurs before any code is run !!


--
If the post is helpful, please consider donating something to an animal
charity on my behalf.


"OssieMac" wrote:

Hi yet again Paul,

I have been doing some testing and found a problem that can send Excel into
a Flip and it has to close. Trying to use the RefEdit value (which is
actually a string) when it will return an invalid range then Excel flips.
Biggest problem is if it is blank and you try to use it but have also found
typing invalid values can do it.

The most complete test I can think of is to attempt to use it to assign to a
range variable and if an error is returned then it is invalid. If it is a
valid range then you can use that range variable to continue your validity
testing to see if it is within the desired range selections.

The following is an example.
Private Sub RefEdit1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

Dim rngTest As Range

'Attempt to assign to a range variable
On Error Resume Next
Set rngTest = Range(Me.RefEdit1.Value)
If Err.Number 0 Then 'Invalid range
MsgBox "Invalid range. Must select a range."
Cancel = True 'Cancels the Exit
Exit Sub
End If

On Error GoTo 0 'Reset error trapping

'Can now use the range variable to test
'if it is within the valid ranges to select.
If rngTest.Column 4 Then
Cancel = True 'Cancels the Exit
MsgBox "Must Select from first 4 columns."
End If

End Sub


As before, feel free to get back to me.

--
Regards,

OssieMac