Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ram Ram is offline
external usenet poster
 
Posts: 138
Default Attaching a function

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Attaching a function

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 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Attaching a function

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 ,
Ram 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
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
Attaching documents to Excel Xt Excel Worksheet Functions 1 November 21st 09 07:47 PM
Attaching a drawing Matt Excel Discussion (Misc queries) 2 June 29th 07 04:02 PM
Attaching PDF files Neil Meehan Excel Discussion (Misc queries) 0 September 23rd 06 04:29 AM
Attaching Help File to a User Defined Function maca Excel Discussion (Misc queries) 0 July 5th 05 02:32 PM
Attaching a particular user defined function to cust button Ajay Excel Discussion (Misc queries) 3 February 23rd 05 08:29 AM


All times are GMT +1. The time now is 10:27 PM.

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

About Us

"It's about Microsoft Excel"