I need to find numbers from a string
. How does one find numbers from a string
in VBA Excel?
相关问题
- how to split a list into a given number of sub-lis
- Excel sunburst chart: Some labels missing
- Generate string from integer with arbitrary base i
- Converting a string array to a byte array
- Error handling only works once
相关文章
- JSP String formatting Truncate
- Selecting only the first few characters in a strin
- Get column data by Column name and sheet name
- Python: print in two columns
- programmatically excel cells to be auto fit width
- Unregister a XLL in Excel (VBA)
- Unregister a XLL in Excel (VBA)
- extending c++ string member functions
Expanding on brettdj's answer, in order to parse disjoint embedded digits into separate numbers:
Use the built-in VBA function Val, if the numbers are at the front end of the string:
lng = 1149
Val Function, on MSDN
This a variant of brettdj's & pstraton post.
This will return a true Value and not give you the
#NUM!
error. And\D
is shorthand for anything but digits. The rest is much like the others only with this minor fix.I was looking for the answer of the same question but for a while I found my own solution and I wanted to share it for other people who will need those codes in the future. Here is another solution without function.
resultval = 1234
Assuming you mean you want the non-numbers stripped out, you should be able to use something like:
Calling this with:
will give you a dialog box containing:
and those first two lines show how you can store it into an arbitrary string variable, to do with as you wish.
Regular expressions are built to parse. While the syntax can take a while to pick up on this approach is very efficient, and is very flexible for handling more complex string extractions/replacements