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

How can I extract few digits from a number?
Example:
6.583 -- 6.5
110.671 -- 110.

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default numers extracting??

Supertramp;

Try this:

=EXTRACTELEMENT(A1;2;" ")
Where A1 is de cel to extract an element from.
2 means the second element.
" " means that the second element is seperated by a space.

Place this code in a VBA module.

Function EXTRACTELEMENT(Txt, n, Separator) As String
' Returns the nth element of a text string, where the elements are
separated by a specified separator character

Dim Txt1 As String, TempElement As String
Dim ElementCount As Integer, i As Integer

Txt1 = Txt
' If space separator, remove excess spaces
If Separator = Chr(32) Then Txt1 = Application.Trim(Txt1)

' Add a separator to the end of the string
If Right(Txt1, Len(Txt1)) < Separator Then _
Txt1 = Txt1 & Separator

' Initialize
ElementCount = 0
TempElement = ""

' Extract each element
For i = 1 To Len(Txt1)
If Mid(Txt1, i, 1) = Separator Then
ElementCount = ElementCount + 1
If ElementCount = n Then
' Found it, so exit
EXTRACTELEMENT = TempElement
Exit Function
Else
TempElement = ""
End If
Else
TempElement = TempElement & Mid(Txt1, i, 1)
End If
Next i
EXTRACTELEMENT = ""
End Function

Mark.

More Excel ? www.rosenkrantz.nl or
---------------------------------------------------------------------


"dreamer " wrote in message
...
How can I extract few digits from a number?
Example:
6.583 -- 6.5
110.671 -- 110.6


---
Message posted from
http://www.ExcelForum.com/



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
Concatenate Numers / Text (Special) Teddy-B Excel Discussion (Misc queries) 2 December 24th 08 04:57 PM
how to converting numers to text Anil showreddy Excel Worksheet Functions 2 December 14th 07 10:09 AM
how to use arabic numers in excel 2003 arimala Excel Discussion (Misc queries) 1 October 22nd 07 09:01 PM
Substituting letters for numers Mike New Users to Excel 4 May 8th 07 04:41 AM
Giving numers value to selections the dude Excel Discussion (Misc queries) 1 May 16th 06 07:44 PM


All times are GMT +1. The time now is 01:58 AM.

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"