Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Need macro to trim characters in column

I have a 100 lines in column A in my excel 2003 spreadsheet, each containing
various lengths of text, and need to trim each cell to contain the first 21
characters only & discard the rest.

I will be greatful if someone can assist me in writing a macro to get this
done that will be equivalent the LEFT formula.

Thankyou.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Need macro to trim characters in column

something like this

for each c in range("a2:a102")
c.value=left(c,len(c)-21)
next

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"TonyV" wrote in message
...
I have a 100 lines in column A in my excel 2003 spreadsheet, each
containing
various lengths of text, and need to trim each cell to contain the first
21
characters only & discard the rest.

I will be greatful if someone can assist me in writing a macro to get this
done that will be equivalent the LEFT formula.

Thankyou.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 897
Default Need macro to trim characters in column

Sub trimit()

Dim cell As Excel.Range

For Each cell In Selection
cell = Left(LTrim(cell), 21)
Next cell

End Sub


HTH,
JP

On Jan 10, 11:21*am, TonyV wrote:
I have a 100 lines in column A in my excel 2003 spreadsheet, each containing
various lengths of text, and need to trim each cell to contain the first 21
characters only & discard the rest.

I will be greatful if someone can assist me in writing a macro to get this
done that will be equivalent the LEFT formula.

Thankyou.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Need macro to trim characters in column

hi.
try this
Sub trimit()
Dim r As Range
Dim rd As Range
Set r = Range("A2") 'assumes header
Do While Not IsEmpty(r)
Set rd = r.Offset(1, 0)
r.Value = Left(r, 21)
Set r = rd
Loop
End Sub

regards
FSt1

"TonyV" wrote:

I have a 100 lines in column A in my excel 2003 spreadsheet, each containing
various lengths of text, and need to trim each cell to contain the first 21
characters only & discard the rest.

I will be greatful if someone can assist me in writing a macro to get this
done that will be equivalent the LEFT formula.

Thankyou.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Need macro to trim characters in column

Sub FiftyChars()
Dim c As Range
With Sheets(1) '<<<<= change to suit
For Each c In .Range("A1:A100") '<<<= change to suit
c.Value = Left(c, 2)
Next
End With
End Sub

"TonyV" wrote:

I have a 100 lines in column A in my excel 2003 spreadsheet, each containing
various lengths of text, and need to trim each cell to contain the first 21
characters only & discard the rest.

I will be greatful if someone can assist me in writing a macro to get this
done that will be equivalent the LEFT formula.

Thankyou.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Need macro to trim characters in column

...oops sorry 21 in the left function below not 2 !

Sub FiftyChars()
Dim c As Range
With Sheets(1)
For Each c In .Range("A1:A100")
c.Value = Left(c, 21)
Next
End With
End Sub

"TonyV" wrote:

I have a 100 lines in column A in my excel 2003 spreadsheet, each containing
various lengths of text, and need to trim each cell to contain the first 21
characters only & discard the rest.

I will be greatful if someone can assist me in writing a macro to get this
done that will be equivalent the LEFT formula.

Thankyou.


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
Trim characters Ronbo Excel Worksheet Functions 7 January 26th 09 09:29 PM
Convert column data to trim all characters and leave the last 6 S Himmelrich Excel Programming 5 December 14th 07 10:14 AM
How do you trim characters? Tommi Excel Worksheet Functions 6 January 29th 06 01:38 PM
Trim the last two characters? Craig[_8_] Excel Programming 4 September 7th 04 02:52 AM
Trim characters Ange[_3_] Excel Programming 1 August 25th 04 07:31 PM


All times are GMT +1. The time now is 02:41 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"