View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default RefEdit Exit not firing

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