Microsoft Excel - extract numbers only - Asked By Dan on 15-Jan-14 08:07 AM

I am trying to extract only the numbers and not the letters or dashes from column H to column AA.

example: TQ096-TTTTT-QQQQQQQQQ

result needed : 096

Dan
Robbe Morris replied to Dan on 15-Jan-14 09:00 AM
public static string GetNumericText(string text)
{
   if (string.IsNullOrEmpty(text)) return string.Empty;
   return System.Text.RegularExpressions.Regex.Replace(text, @"(?i)[^0-9]", string.Empty).Trim();
}
Harry Boughen replied to Dan on 15-Jan-14 07:20 PM
Hi Dan

=1*MID(H1,MATCH(TRUE,ISNUMBER(1*MID(H1,ROW($1:$9),1)),0),COUNT(1*MID(H1,ROW($1:$9),1)))

Enter this as an array formula.  The only problem is that when 096 displays it appears as 96 so you might have to convert it to text and use a format to preserve the leading zero.  The success or not of this will depend on whether the number of digits to be extracted is variable or not.
Regards
Harry
Robbe Morris replied to Robbe Morris on 16-Jan-14 11:22 AM
Ah geez, I didn't notice this was an Excel question.  Duh.  Well, I'll leave this up here just in case someone needs to the RegEx for stripping everything but numbers from a string in C# .NET.