Need to create URL variations

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,064
Office Version
  1. 2016
Platform
  1. Windows
Hi

I have been stuck on this one for sometime now and need so help, please. I need a code that will create variations of urls.

In Sheet 1 I will have a list of urls, column A row 2 down. Some urls may NOT end with a forward slash, the urls will also end with different prefix .com .co.uk .org and so on.
1591012413268.png


In Sheet2 I will have the variations I need it to create of the url.
1591012502872.png


When the command button is clicked I need the following to be created, in Sheet1 Column A Row 2 Down. The red colour is only for your reference its is not necessary.
1591012717774.png


I am not sure if it is possible to delete everything after the prefix e.g. .com .co.uk and so on in the url BEFORE it created the variation of the url.

I can not seem to work it out. As always thanks in advance.
 
Last edited:

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi, here is some code you can try.

VBA Code:
Sub m()
Dim a As Variant, b As Variant, c() As String, i As Long, j As Long, k As Long

With Sheets("Sheet1")
    a = .Range("A2:A" & .Range("A" & .Rows.Count).End(xlUp).Row).Value
End With

With Sheets("Sheet2")
    b = .Range("A2:A" & .Range("A" & .Rows.Count).End(xlUp).Row).Value
End With

ReDim c(1 To UBound(a) * UBound(b))

For i = 1 To UBound(a)
    For j = 1 To UBound(b)
        k = k + 1
        c(k) = a(i, 1) & IIf(Right(a(i, 1), 1) = "\", "", "\") & b(j, 1)
    Next j
Next i

Sheets("Sheet1").Range("A2").Resize(k).Value = Application.Transpose(c)

End Sub
 
Upvote 0
FormR

This is super so far and the first half works super.

Results
1591016003862.png



Just does not do this bit "I am not sure if it is possible to delete everything after the prefix e.g. .com .co.uk and so on in the url BEFORE it created the variation of the url. "

Starting URLS
1591015371092.png


Results - The red results are wrong, they should look like the green results.
1591015890185.png


Not too sure how this would be done as urls will be different sizes and will have different prefix .org .com. .uk .co.uk .biz and so on
 
Upvote 0
I'm not to sure what you mean by "definitive" are you stating an actual url list as in my example i am using made up urls OR are you stating "definitive" as an actual FORMAT of urls e.g. AFTER the prefix .com .co.uk and so on there can be no further text so the code works.

Example Actual URLS
Start -
These are actual urls and the results are shown below.
1591020204918.png

Results - All these result are wrong
1591020300145.png

They should look like this

1591020374310.png


URL FORMAT
Or do you mean that the urls need to be cleaned and have a SET FORMAT SO
These URLS

1591020430475.png

NEED to look like this before the code is run
1591020500279.png


As I was hoping a code would do this before it creates the variations. See Below
1591020577768.png
 
Upvote 0
Hi, I mean a list of domain names i.e
.com
.co.uk
.cn
etc..

As an aside, you should consider installing the XL2BB add-in to post your example data instead of posting images as it allows your potential helpers to copy your data into Excel instead of having to manually re-type it (which can put many people of helping).
 
Upvote 0
Thanks for the up date. I was hoping a code could format the urls but there are too many variations to domains, never mind. i will make do as is thanks for your support.

ps - just done it as advised
1591023039718.png
 
Upvote 0
Hi, I've had a bit more time this morning to digest this, I think this does what you want.

VBA Code:
Sub m()
Dim a As Variant, b As Variant, c() As String, i As Long, j As Long, k As Long

With Sheets("Sheet1")
    a = .Range("A2:A" & .Range("A" & .Rows.Count).End(xlUp).Row).Value
End With

With Sheets("Sheet2")
    b = .Range("A2:A" & .Range("A" & .Rows.Count).End(xlUp).Row).Value
End With

ReDim c(1 To UBound(a) * UBound(b))

For i = 1 To UBound(a)
    For j = 1 To UBound(b)
        k = k + 1
        c(k) = Left(a(i, 1) & "\", InStr(9, a(i, 1) & "\", "\")) & b(j, 1)
    Next j
Next i

Sheets("Sheet1").Range("A2").Resize(k).Value = Application.Transpose(c)

End Sub
 
Upvote 0
Super, this is exactly what I was after.

Thanks FormR
There was however one slight problem with your code, luckly it was within my programing skills to fix this major problem. I changed the BackSlash "\" to a ForwardSlash "/" ?????. Its all good now " Some urls may NOT end with a forward slash, "
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,921
Members
449,094
Latest member
teemeren

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