View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
J_Knowles J_Knowles is offline
external usenet poster
 
Posts: 28
Default Function/Macro that keeps first X characters in a cell and delets

Try this out:

Sub leftXChrs()
'keeps left x characters of a selected range
Dim c As Range
Dim mychrs As Long
On Error Resume Next
mychrs = InputBox("Be sure to select a range of cells. " _
& Chr(13) & "How many characters to keep?", 1)
If mychrs = False Or Not Application.IsNumber(mychrs) Then
Exit Sub
End If
For Each c In Selection
c.Value = Left(c.Value, mychrs)
Next c
End Sub

HTH,
--
Data Hog


"andrei" wrote:


So , i need a macro/function that keeps the first X characters in a cell
( the number is given ) and deletes the remaining characters

Example

In a cell i have the following text : *Mother and father*
I want the macro to keep the first 8 characters . So , in that cell ,
the result should be : *Mother a* . When i mean charcaters , i take into
consideration letter , space or number


--
andrei
------------------------------------------------------------------------
andrei's Profile: 1056
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=167722

Microsoft Office Help

.