ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Strings and numbers in cells (https://www.excelbanter.com/excel-discussion-misc-queries/157097-strings-numbers-cells.html)

lespal

Strings and numbers in cells
 
Is there a way to make Excel only recognise numbers in a cell when the cell
contains both numbers and a string?

lespal

Kevin B

Strings and numbers in cells
 
The following UDF might do what you want it to. It loops through a string
value and concatenates numeric strings and returns the result as a long
integer.

Function ReturnNums(StringVal) As Long


Dim intLen As Integer
Dim i As Integer
Dim strReturnVal As String
Dim strChar As String

intLen = Len(StringVal)


For i = 1 To intLen
strChar = Mid(StringVal, i, 1)
If IsNumeric(strChar) Then strReturnVal = strReturnVal & strChar
Next i

If Len(strReturnVal) = 0 Then
ReturnNums = 0
Else
ReturnNums = CLng(strReturnVal)
End If


End Function
--
Kevin Backmann


"lespal" wrote:

Is there a way to make Excel only recognise numbers in a cell when the cell
contains both numbers and a string?

lespal



All times are GMT +1. The time now is 04:46 AM.

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