View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Paige Paige is offline
external usenet poster
 
Posts: 270
Default Trim Conflicts with Data Validation

I have the following data val for a merged cell (E8:F8) with the range name
of SVCTYPE:

Private Sub Worksheet_SelectionChange(ByVal target As Range)
With Range("SVCTYPE").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="MMS,Repair,Convert"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = "Invalid entry."
.ShowInput = True
.ShowError = True
End With
End Sub

Also have the following, whose intent is to trim any excess spaces in case
the user decides to manually enter the response and accidentally adds spaces
to the end for instance.

Private Sub Worksheet_Change(ByVal target As Range)
If Not Intersect(target, Range("$E$8:$F$8")) Is Nothing Then
target.Value = Trim(target.Value)
End If
End Sub

Problems a 1) If there is an entry in the cell and the user deletes it, I
get a type/mismatch error with the target.Value = Trim(target.value) line of
code. 2) If I use the drop-down to select an entry, the code seems to get
stuck in 'calculating cells' and goes on and on. When I take out the trim
function, everything works fine. Can someone advise what I'm doing wrong?