ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   A Simple Trim (https://www.excelbanter.com/excel-discussion-misc-queries/220289-simple-trim.html)

N1KO

A Simple Trim
 
I need to trim a series of cells so they only contain 241 characters. Does
anyone have any VBA code to make this quick and easy?

It needs to be the 1st 241 characters, everything else after that can be
deleted however i don't think i can use an =Right or =Trim to my knowledge as
the amount of characters in the cell isn't always the same (Anywhere between
40 & 390characters).

Mike H

A Simple Trim
 
Hi,

It doesn't matter if there are less than 241 characters, this works

myvalue = Left(myvalue, 241)

Mike

"N1KO" wrote:

I need to trim a series of cells so they only contain 241 characters. Does
anyone have any VBA code to make this quick and easy?

It needs to be the 1st 241 characters, everything else after that can be
deleted however i don't think i can use an =Right or =Trim to my knowledge as
the amount of characters in the cell isn't always the same (Anywhere between
40 & 390characters).


Ron Rosenfeld

A Simple Trim
 
On Wed, 11 Feb 2009 04:37:19 -0800, N1KO
wrote:

I need to trim a series of cells so they only contain 241 characters. Does
anyone have any VBA code to make this quick and easy?

It needs to be the 1st 241 characters, everything else after that can be
deleted however i don't think i can use an =Right or =Trim to my knowledge as
the amount of characters in the cell isn't always the same (Anywhere between
40 & 390characters).


What about =left(a1,241)

You could put that in a helper column, fill down, then copy/paste-values to get
rid of the formula and also replace the original.
--ron

curlydave

A Simple Trim
 
On Feb 11, 5:37*am, N1KO wrote:
I need to trim a series of cells so they only contain 241 characters. Does
anyone have any VBA code to make this quick and easy?

It needs to be the 1st 241 characters, everything else after that can be
deleted however i don't think i can use an =Right or =Trim to my knowledge as
the amount of characters in the cell isn't always the same (Anywhere between
40 & 390characters).


I beleive this should work

=IF(LEN(A1)241,LEFT(A1,241),A1)

curlydave

A Simple Trim
 
"Oh Ya!, that's right what Mike said" , I replied foolishly

Mike H

A Simple Trim
 
Hi,

If you go for a worksheet solution then there's no need to test if the
string is 241 long with an IF

=left(a1,241)

is sufficient even for shorter strings.

Mike

"CurlyDave" wrote:

"Oh Ya!, that's right what Mike said" , I replied foolishly


curlydave

A Simple Trim
 
On Feb 11, 6:10*am, Mike H wrote:
Hi,

If you go for a worksheet solution then there's no need to test if the
string is 241 long with an IF

=left(a1,241)

is sufficient even for shorter strings.

Mike

"CurlyDave" wrote:
"Oh Ya!, that's right what Mike said" , I replied foolishly


......"Oh Ya!, that's right what Mike said" , I replied
foolishly........
I was agreeing with you, I couldn't believe I didn't think of it.


All times are GMT +1. The time now is 08:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com