Remove anything after the 3rd / and append some data

mvrht

New Member
Joined
Dec 9, 2017
Messages
18
We have various urls posted into our sheet that sometimes are not valid urls for what we need. So we need to strip some data from it and append some data to the end.

EXAMPLE
Code:
https://www.myurl.com/p/Bce6o9tg0XZ/?utm_source=google&utm_medium=cpc
needs stripping to
Code:
https://www.myurl.com/p/Bce6o9tg0XZ/
and then appending with
refer/?size=web

Leaving me with
Code:
https://www.myurl.com/p/Bce6o9tg0XZ/refer/?size=web
Ideally this needs doing on the fly, so when an invalid url is entered. The function converts it and adds the part on the end, so perhaps I can apply a function to the column or within Google App Script using Javascript

I have had a tinker with the functions here which only deal with the extraction part but no joy yet
https://stackoverflow.com/questions/20717566/excel-remove-everything-after-in-a-url
 
Last edited by a moderator:

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
mvrht,

Welcome to the MrExcel Forum.

My PC was just recently upgraded to the latest version of Windows 10.

You first three links are returning: This site is not secure
 
Upvote 0
mvrht,

Welcome to the MrExcel Forum.

My PC was just recently upgraded to the latest version of Windows 10.

You first three links are returning: This site is not secure
Windows 8.1 is balking also. It says the "https" security designation is not correct and that the site is actually not secure at all. Given that, I think it would be prudent for the OP to do a virus scan on his computer since he obviously visited the underlying website.
 
Last edited:
Upvote 0
I am surprised that hiker even clicked on the links. Given that this is your first post and your question is pretty dependent on clicking the links, there is no way I am clicking.

You may want to find a way to describe what your requirements without the links.
 
Upvote 0
Windows 8.1 is balking also. It says the "https" security designation is not correct and that the site is actually not secure at all. Given that, I think it would be prudent for the OP to do a virus scan on his computer since he obviously visited the underlying website.

Or he would like others to click on the links, if you catch my drift.
 
Upvote 0
In the meantime, if he/she wants to continue visiting sites that are not secure, this might do it (not automatically though).
Code:
Sub Maybe()
Dim c As Range, a
For Each c In Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row)
	a = Split(c, "/")
	c.Offset(, 2).Value = Left(c, Len(c) - Len(a(UBound(a)))) & "refer/?size=web"
Next c
End Sub
 
Upvote 0
I was thinking that the links weren't links per-se, but simply examples of what the OP was trying to achieve.
 
Upvote 0
I was thinking that the links weren't links per-se, but simply examples of what the OP was trying to achieve.
Assuming you are correct, then I think this formula will produce the results the OP wants...

=LEFT(A1,FIND("",SUBSTITUTE(A1,"/","",5)))&"refer/?size=web"
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,213
Members
452,618
Latest member
Tam84

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