Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
...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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Trim characters | Excel Worksheet Functions | |||
Convert column data to trim all characters and leave the last 6 | Excel Programming | |||
How do you trim characters? | Excel Worksheet Functions | |||
Trim the last two characters? | Excel Programming | |||
Trim characters | Excel Programming |