ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Extract 2, 3, 4 or 5-digit number from string (https://www.excelbanter.com/excel-programming/331056-extract-2-3-4-5-digit-number-string.html)

Jim[_55_]

Extract 2, 3, 4 or 5-digit number from string
 
I have a list of URLs where some contain the parameter "categoryid="
with either a 2, 3, 4, or 5 digit number. I need to extract that
number, as an integer, into a neighboring column. I need a routine or
function to help with this - something along the line of making the mid
function smart enough to recognize numbers and adjust the length value
so it only takes the numbers. And if it doesn't find "categoryid",
then leave the cell blank.

TIA,
Jim


barrfly[_5_]

Extract 2, 3, 4 or 5-digit number from string
 

Jim,
If the text string is in cell D6 - try this.

=IF(ISERROR(SEARCH("categoryid=",D6)),"",MID(D6,SE ARCH("categoryid=",D6)+11,LEN(D6)-SEARCH("categoryid=",D6)+11))

This function assumes that the numbers are on the end of the text
string. if there is a constant text ending - such as ".com" or
something, simply subtract the length of that string ending from the
mid function.


--
barrfly

Excel User - Energy markets
------------------------------------------------------------------------
barrfly's Profile: http://www.excelforum.com/member.php...fo&userid=4141
View this thread: http://www.excelforum.com/showthread...hreadid=376856



All times are GMT +1. The time now is 10:32 AM.

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