Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Dear all,
I want to get only number from cells in Excel, for example, "$123m/di" in a cell, I want "123" left. I tried Value function in Excel, it doesn't work. I remeber I'v seen a article before, which mentioned how to extract number or text from cells in Excel. But I forgot how to do it totally. Or can I do it in some function? Thanks. JIANG |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I believe you could use a VBScript Regular Expression.
-or- Sub test() Dim str As String, i As Long, j As Long str = "$123m/di" i = 1: Do Until IsNumeric(Mid(str, i, 1)) Or i Len(str): i = i + 1: Loop j = 1: Do Until Not IsNumeric(Mid(str, i, j)) Or i + j - 1 Len(str): j = j + 1: Loop str = Mid(str, i, j - 1) MsgBox str End Sub It's pretty "simple" so it won't do certain numeric things. It handles decimal points but doesn't handle unary operators (eg. -123.4) Let me know if minus signs are a requirement? -- Rob van Gelder - http://www.vangelder.co.nz/excel "Kortrijker" wrote in message ... Dear all, I want to get only number from cells in Excel, for example, "$123m/di" in a cell, I want "123" left. I tried Value function in Excel, it doesn't work. I remeber I'v seen a article before, which mentioned how to extract number or text from cells in Excel. But I forgot how to do it totally. Or can I do it in some function? Thanks. JIANG |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
- or -
you could use strip the first bunch of alphanumerics then use the Val Function on the rest. -- Rob van Gelder - http://www.vangelder.co.nz/excel "Rob van Gelder" wrote in message ... I believe you could use a VBScript Regular Expression. -or- Sub test() Dim str As String, i As Long, j As Long str = "$123m/di" i = 1: Do Until IsNumeric(Mid(str, i, 1)) Or i Len(str): i = i + 1: Loop j = 1: Do Until Not IsNumeric(Mid(str, i, j)) Or i + j - 1 Len(str): j = j + 1: Loop str = Mid(str, i, j - 1) MsgBox str End Sub It's pretty "simple" so it won't do certain numeric things. It handles decimal points but doesn't handle unary operators (eg. -123.4) Let me know if minus signs are a requirement? -- Rob van Gelder - http://www.vangelder.co.nz/excel "Kortrijker" wrote in message ... Dear all, I want to get only number from cells in Excel, for example, "$123m/di" in a cell, I want "123" left. I tried Value function in Excel, it doesn't work. I remeber I'v seen a article before, which mentioned how to extract number or text from cells in Excel. But I forgot how to do it totally. Or can I do it in some function? Thanks. JIANG |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Dear Rob,
Thanks a lot for your prompt and great reply. minus signs are not a requirement. best regards JIANG |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to extract the number of pages in a cell (Excel 2003) | Excel Discussion (Misc queries) | |||
How do I extract the decimal places from a number in excel? | Excel Worksheet Functions | |||
How do extract cells from hundreds of excel files and put in one n | Excel Discussion (Misc queries) | |||
Excel Changes Text Cells to Number Cells When Importing XML | Excel Discussion (Misc queries) | |||
excel format cells/Number/Category: Number problem | Excel Discussion (Misc queries) |