Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
EAK EAK is offline
external usenet poster
 
Posts: 1
Default User Defined FUNCTION

I need a User Defined Function that check if a number or string is 8 digits
long and ends in "0000". If it meets the two creteria, then it should drop
those the "0000" and return only the remaining 4 numbers for example,

23000016 result 23000016
23160000 result 2316
19000000 result 1900

FYI using Substitute() gives me the wrong result sometimes.

FUNCTION Truc(location)

END Function
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,420
Default User Defined FUNCTION

IF(AND(LEN(A1)=8,RIGHT(A1,4)="0000"),LEFT(A1,4),A1 )

--
__________________________________
HTH

Bob

"EAK" wrote in message
...
I need a User Defined Function that check if a number or string is 8 digits
long and ends in "0000". If it meets the two creteria, then it should drop
those the "0000" and return only the remaining 4 numbers for example,

23000016 result 23000016
23160000 result 2316
19000000 result 1900

FYI using Substitute() gives me the wrong result sometimes.

FUNCTION Truc(location)

END Function



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default User Defined FUNCTION

As opposed to a udf how about this...

=IF(RIGHT(A1, 4) = "0000", A1/10000, A1)
--
HTH...

Jim Thomlinson


"EAK" wrote:

I need a User Defined Function that check if a number or string is 8 digits
long and ends in "0000". If it meets the two creteria, then it should drop
those the "0000" and return only the remaining 4 numbers for example,

23000016 result 23000016
23160000 result 2316
19000000 result 1900

FYI using Substitute() gives me the wrong result sometimes.

FUNCTION Truc(location)

END Function

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default User Defined FUNCTION

Give this UDF a try (assuming you wanted it named Truc as posted)...

Function Truc(S As String) As String
If S Like "????0000" Then
Truc= Left(S, 4)
Else
Truc= S
End If
End Function

Rick


"EAK" wrote in message
...
I need a User Defined Function that check if a number or string is 8 digits
long and ends in "0000". If it meets the two creteria, then it should drop
those the "0000" and return only the remaining 4 numbers for example,

23000016 result 23000016
23160000 result 2316
19000000 result 1900

FYI using Substitute() gives me the wrong result sometimes.

FUNCTION Truc(location)

END Function


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 964
Default User Defined FUNCTION

Why would you even use SUBSTITUTE?

=IF(AND(LEN(A1)=8,RIGHT(TRIM(A1),4)="0000"),TRUNC( A1,4)/10000,A1)


--


Regards,


Peo Sjoblom

"EAK" wrote in message
...
I need a User Defined Function that check if a number or string is 8 digits
long and ends in "0000". If it meets the two creteria, then it should drop
those the "0000" and return only the remaining 4 numbers for example,

23000016 result 23000016
23160000 result 2316
19000000 result 1900

FYI using Substitute() gives me the wrong result sometimes.

FUNCTION Truc(location)

END Function





  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default User Defined FUNCTION

The OP mentioned he wanted this only if the number is 8 digits long as well.
True, his examples all show 8-digit numbers, but I made the same kind of
assumption in another thread yesterday and my assumption turned out to be
wrong. So, just in case...

=IF(AND(RIGHT(A1,4)="0000",LEN(A1)=8),A1/10000,A1)

Rick


"Jim Thomlinson" wrote in message
...
As opposed to a udf how about this...

=IF(RIGHT(A1, 4) = "0000", A1/10000, A1)
--
HTH...

Jim Thomlinson


"EAK" wrote:

I need a User Defined Function that check if a number or string is 8
digits
long and ends in "0000". If it meets the two creteria, then it should
drop
those the "0000" and return only the remaining 4 numbers for example,

23000016 result 23000016
23160000 result 2316
19000000 result 1900

FYI using Substitute() gives me the wrong result sometimes.

FUNCTION Truc(location)

END Function


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
user defined function Pete_T Excel Worksheet Functions 1 December 1st 07 01:03 AM
User Defined Function Barb Reinhardt Excel Worksheet Functions 3 March 28th 07 02:23 AM
user defined function driller Excel Worksheet Functions 1 November 18th 06 04:51 PM
user defined function delmac Excel Worksheet Functions 1 August 11th 06 04:31 PM
User defined function linzhang426 New Users to Excel 4 October 10th 05 03:18 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"