View Single Post
  #31   Report Post  
Posted to microsoft.public.excel.programming
AAA[_3_] AAA[_3_] is offline
external usenet poster
 
Posts: 4
Default limiting characters in a cell

good morning..
concerning the empty cell, yes, i want to fill it with white spaces
too, and the code down solves this problem,but i still have a small
problem,"see down":
"""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)


Dim myRngToCheck As Range
Dim myCell As Range
Dim myLengths As Variant
Dim myCols As Variant
Dim iCol As Long


myCols = Array(1, 2, 3, 4) 'A, E, L
myLengths = Array(20, 30, 13, 10)


Set myRngToCheck = Me.Columns(myCols(LBound(myCols)))
For iCol = LBound(myCols) + 1 To UBound(myCols)
Set myRngToCheck = Union(myRngToCheck,
Me.Columns(myCols(iCol)))
Next iCol


If Intersect(Target, myRngToCheck) Is Nothing Then
Exit Sub
End If


On Error Resume Next 'just keep going!
Application.EnableEvents = False
For Each myCell In Intersect(Target, myRngToCheck).Cells
'the arrays are 0 based, so we subtract 1 from the match
iCol = Application.Match(myCell.Column, myCols, 0) - 1
myCell.Value _
= Left(myCell.Value & Space(myLengths(iCol)),
myLengths(iCol))
Next myCell
Application.EnableEvents = True
On Error GoTo 0


End Sub
"""""""""""""""""""""""""""""""""""""""""""""""""" """"""
this code works very good, the only problem i'm facing is that when the
data in a cell is of type " standard" or " number" or anything
else,filling the rest of the characters with empty space is not
working.Only when its in the form of a text, do i always have to change
it to text to use it, or there is a way...
one more question, when i copy data from excel to word, a tab(big empty
space) instead of the lines seperating the columns always exsits, is
it possible to remove it..
thank you a lot, promise to stop bothering you with my problem.