PC Review


Reply
Thread Tools Rate Thread

Attaching a function

 
 
=?Utf-8?B?UmFt?=
Guest
Posts: n/a
 
      31st Oct 2007
I have an excel worksheet. A user enters data in a cell. But he can enter the
data with leading and traliling spaces. So after the user enters data in the
cell, I want to attach like TRIM function to remove the spaces in the same
cell. Can some one help me how to do this?
Thank you
 
Reply With Quote
 
 
 
 
Gord Dibben
Guest
Posts: n/a
 
      31st Oct 2007
In the same cell?

You would need event code to do that as the data is entered.

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("A1:A20"), Target) Is Nothing Then
On Error GoTo endit
Application.EnableEvents = False

If (Not IsEmpty(Target)) And _
Not IsNumeric(Target.Value) And _
InStr(Target.Formula, "=") = 0 _
Then Target.Value = Application.Trim(Target.Value)
End If
endit:
Application.EnableEvents = True
End Sub


Gord Dibben MS Excel MVP

On Wed, 31 Oct 2007 14:23:00 -0700, Ram <(E-Mail Removed)> wrote:

>I have an excel worksheet. A user enters data in a cell. But he can enter the
>data with leading and traliling spaces. So after the user enters data in the
>cell, I want to attach like TRIM function to remove the spaces in the same
>cell. Can some one help me how to do this?
>Thank you


 
Reply With Quote
 
JE McGimpsey
Guest
Posts: n/a
 
      31st Oct 2007
To do so would require an event macro. Put this in your worksheet code
module:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim rArea As Range
Dim rCell As Range
On Error GoTo ErrorOrExit
Application.EnableEvents = False
For Each rArea In Target
For Each rCell In rArea
With rCell
If Not .HasFormula Then _
If Not IsNumeric(.Value) Then _
.Value = Trim(.Value)
End With
Next rCell
Next rArea
ErrorOrExit:
Application.EnableEvents = True
End Sub



But one can usually work around the problem by using TRIM() in any
formulas that reference the cell.

In article <D13252E4-D0F0-4B65-9ACD-(E-Mail Removed)>,
Ram <(E-Mail Removed)> wrote:

> I have an excel worksheet. A user enters data in a cell. But he can enter the
> data with leading and traliling spaces. So after the user enters data in the
> cell, I want to attach like TRIM function to remove the spaces in the same
> cell. Can some one help me how to do this?
> Thank you

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Attaching files in Word 2000 like attaching files to email =?Utf-8?B?UyB0cmFpbmVy?= Microsoft Word Document Management 1 23rd Dec 2006 08:54 PM
Attaching a check box to a max date function Chris W via AccessMonster.com Microsoft Access Queries 5 12th Oct 2005 02:32 AM
Attaching Help File to a User Defined Function maca Microsoft Excel Misc 0 5th Jul 2005 02:32 PM
Attaching a particular user defined function to cust button =?Utf-8?B?QWpheQ==?= Microsoft Excel Misc 3 23rd Feb 2005 08:29 AM
Attaching Tables Stephen Lebans Function Attaching Tables Microsoft Access VBA Modules 1 14th Jan 2004 11:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:56 PM.