ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   numers extracting?? (https://www.excelbanter.com/excel-programming/292622-numers-extracting.html)

dreamer[_16_]

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


Mark Rosenkrantz[_2_]

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/





All times are GMT +1. The time now is 11:29 AM.

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