LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
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?

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto-Trim through validation or the macro SG Excel Worksheet Functions 1 August 7th 07 03:38 PM
Trim and Keep the Trimmed Data sally t Excel Worksheet Functions 2 July 26th 05 02:29 PM
Trim Data in a Query Jonathan Excel Programming 3 May 22nd 05 10:55 PM
Trim data in charts jrgarcia79 Charts and Charting in Excel 4 May 16th 05 04:45 PM
VBA Trim and Application.worksheetfunction.Trim Hari Prasadh Excel Programming 3 January 19th 05 02:22 PM


All times are GMT +1. The time now is 08:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"