Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default trimming cell contents?

Hi

I have a column of cells each containing a 4 digit number. Is there any way
I can trim the left digit dependant upon certain conditions.

If the left digit of each 4 digit number equals either "1" or "2" I want to
trim this away. If the original 4 digit number ends in anything other than
"1" or "2" I want to leave the original 4 digit number unaltered.

For example:

1231 would become 123
1232 would become 123
1234 would stay as 1234

Any help on this is really appreciated.

Many thanks in advance

Jem


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default trimming cell contents?

Hi
you can use a worksheet function,

=VALUE(IF(OR(RIGHT(A1,1) = "1", RIGHT(A1,1) = "2"),LEFT(A1,3),A1))

assumimng your number is in A1. The VALUE bit ensures a number is
returned
regards
Paul
Jeremy Turner wrote:
Hi

I have a column of cells each containing a 4 digit number. Is there any way
I can trim the left digit dependant upon certain conditions.

If the left digit of each 4 digit number equals either "1" or "2" I want to
trim this away. If the original 4 digit number ends in anything other than
"1" or "2" I want to leave the original 4 digit number unaltered.

For example:

1231 would become 123
1232 would become 123
1234 would stay as 1234

Any help on this is really appreciated.

Many thanks in advance

Jem


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default trimming cell contents?

Thanks for the prompt reply, it's really appreciated !

Cheers

Jem


wrote in message
oups.com...
Hi
you can use a worksheet function,

=VALUE(IF(OR(RIGHT(A1,1) = "1", RIGHT(A1,1) = "2"),LEFT(A1,3),A1))

assumimng your number is in A1. The VALUE bit ensures a number is
returned
regards
Paul
Jeremy Turner wrote:
Hi

I have a column of cells each containing a 4 digit number. Is there any
way
I can trim the left digit dependant upon certain conditions.

If the left digit of each 4 digit number equals either "1" or "2" I want
to
trim this away. If the original 4 digit number ends in anything other
than
"1" or "2" I want to leave the original 4 digit number unaltered.

For example:

1231 would become 123
1232 would become 123
1234 would stay as 1234

Any help on this is really appreciated.

Many thanks in advance

Jem




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default trimming cell contents?

Sub TrimData()
Dim l as Long, r as long
Dim cell as Range
for each cell in selection
if len(cell) = 4 and isnumeric(cell) then
l = Left(cell,1)
r = right(cell,1)
if (l = 1 or l = 2) and (r = 1 or r = 2) then
cell.Value = Right(cell.value,3)
end if
end if
Next
End Sub

--
Regards,
Tom Ogilvy



"Jeremy Turner" wrote:

Hi

I have a column of cells each containing a 4 digit number. Is there any way
I can trim the left digit dependant upon certain conditions.

If the left digit of each 4 digit number equals either "1" or "2" I want to
trim this away. If the original 4 digit number ends in anything other than
"1" or "2" I want to leave the original 4 digit number unaltered.

For example:

1231 would become 123
1232 would become 123
1234 would stay as 1234

Any help on this is really appreciated.

Many thanks in advance

Jem



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
Trimming text from the end of cell contents. Colin Hayes Excel Worksheet Functions 8 September 1st 09 01:07 AM
concatenate contents of cells whose contents resemble cell referem cathyh Excel Worksheet Functions 3 May 23rd 09 12:16 PM
Trimming cell contents? Jeremy Turner Excel Worksheet Functions 4 June 19th 06 03:00 PM
Trimming a cell down to 256 Characters method373 Excel Discussion (Misc queries) 2 February 12th 06 02:59 PM
Macro to remove contents of cell and move all other contents up one row adw223 Excel Discussion (Misc queries) 1 July 1st 05 03:57 PM


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