Return where a number is found in a URL string, only if it is found after a certain number of "/" characters

chive90

Board Regular
Joined
May 3, 2023
Messages
56
Office Version
  1. 2016
In C2 I have a URL
In D2 I have a number that is also present in the URL
In J2 I would like to enter a formula that returns a Yes/No if the number in D2 is found in a certain location in C2

A Yes should only be returned if the number is present in the URL string of text between the 8th and 9th "/" character.

If it is found as a single instance before the 8th or after the 9th "/" then a No should be returned. The only caveat to this is if the number is in the URL twice, but one instance is in the correct location (i.e. after the 8th but before the 9th "/") then a Yes should be returned regardless of where the second instance is found.

Thank you
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
try:
Excel Formula:
=IF(FIND(D2,SUBSTITUTE(C2,"/","#",8))<FIND("/",SUBSTITUTE(C2,"/","#",8)),"Yes","No")
"#" should be any character that will never be in the URLs
 
Upvote 0
1. What if you have a 8th "/" then the number but you don't have a 9th "/"? Should that also return yes? Or is this never going to happen?
2. If for example the number is "1234", would it appear in the URL like this?: "firstpartofURL/1234/lastpartofURL" or could it be like this "firstpartofURL/asdf1234asdf/lastpartofURL", that is the number with other characters?
 
Last edited:
Upvote 0
Considering that 9th "/" hast to be present, and that It can be just the number or the number mixed with other characters between 8th and 9th "/"... how about?:

Cell Formulas
RangeFormula
J2:J8J2=IF(ISNUMBER(SEARCH(D2, TEXTBEFORE(TEXTAFTER(C2, "/", 8), "/"))), "yes", "no")
 
Upvote 0
try:
Excel Formula:
=IF(FIND(D2,SUBSTITUTE(C2,"/","#",8))<FIND("/",SUBSTITUTE(C2,"/","#",8)),"Yes","No")
"#" should be any character that will never be in the URLs

Thanks. This seems to all return "No", despite the number existing. Is this because the number in cell D2 is just the Number, whereas in C2 it is part of a wider string of text between the "/" characters? For example in D2 it might be: 64045465

But in C2 between the 8th and 9th / it might be "text text 64045465"

This should return Yes.

1. What if you have a 8th "/" then the number but you don't have a 9th "/"? Should that also return yes? Or is this never going to happen?
2. If for example the number is "1234", would it appear in the URL like this?: "firstpartofURL/1234/lastpartofURL" or could it be like this "firstpartofURL/asdf1234asdf/lastpartofURL", that is the number with other characters?

Never going to happen. 9th "/" will always be present as each URL ends with a "/".

And yes to your second point which may be why the formula posted by the other user is returning No.

In C2 between the 8th and 9th / it might be "text text 64045465" - in fact it almost always will be with text and rarely the number just by itself - but as this number is still found between the 8th and 9th "/" it should return a Yes.
 
Upvote 0
Considering that 9th "/" hast to be present, and that It can be just the number or the number mixed with other characters between 8th and 9th "/"... how about?:

Cell Formulas
RangeFormula
J2:J8J2=IF(ISNUMBER(SEARCH(D2, TEXTBEFORE(TEXTAFTER(C2, "/", 8), "/"))), "yes", "no")

Thank you but I am using Excel 2016 and I do not believe TEXTBEFORE to be a function compatible with this version? Is there an alternative?
 
Upvote 0
My mistake, here is the formula for 2016:

Cell Formulas
RangeFormula
J2:J8J2=IF(ISNUMBER(SEARCH(D2, MID(C2, SEARCH("\", SUBSTITUTE(C2, "/", "\", 8))+1,SEARCH("\", SUBSTITUTE(C2, "/", "\", 9))-SEARCH("\", SUBSTITUTE(C2, "/", "\", 8))-1))), "yes", "no")


Let me know if it works for you.
 
Upvote 1
My mistake, here is the formula for 2016:

Cell Formulas
RangeFormula
J2:J8J2=IF(ISNUMBER(SEARCH(D2, MID(C2, SEARCH("\", SUBSTITUTE(C2, "/", "\", 8))+1,SEARCH("\", SUBSTITUTE(C2, "/", "\", 9))-SEARCH("\", SUBSTITUTE(C2, "/", "\", 8))-1))), "yes", "no")


Let me know if it works for you.

Thank you, this seems to work really well! Appreciate it :)

I am just being picky now but is there any way to amend the formula so that if the number cell (D2) is blank, it returns a blank in J2?

At present, it returns "Yes" if either the number is found in the correct location, or if the number cell is blank. It returns "No" if the number is found in a different location within the URL which is great.

If it could return a blank if there is no number present in D, that would be brilliant. That way I can differentiate between all 3 outcomes. Thank you
 
Upvote 0
Thanks for the feedback.
Try this:

Excel Formula:
=IF(D2="", "", IF(ISNUMBER(SEARCH(D2, MID(C2, SEARCH("\", SUBSTITUTE(C2, "/", "\", 8))+1,SEARCH("\", SUBSTITUTE(C2, "/", "\", 9))-SEARCH("\", SUBSTITUTE(C2, "/", "\", 8))-1))), "yes", "no"))
 
Upvote 1
Solution

Forum statistics

Threads
1,223,877
Messages
6,175,138
Members
452,614
Latest member
MRSWIN2709

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top