Extract part of hyperlink?

TheWennerWoman

Active Member
Joined
Aug 1, 2019
Messages
270
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have been copying and pasting results from a backgammon site:

Capture2.PNG


If I hover over the first hyperlink in the "Result" column, I see this (it will vary depending on who I was playing, of course):
Code:
https://zooescape.com/backgammon.pl?v=200&gid=5275015&p1=TheWennerWoman&p2=rabsnake

Is there a way of extracting the gid from here (game i.d)? In this case, I'd like to copy 5275015 and paste it into column J.

Many thanks for reading.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Maybe this user defined function:
VBA Code:
Function GetGid(ByRef myRan As Range) As Variant
Dim myHL As String, gdStart As Long
'
myHL = myRan.Hyperlinks(1).Address
gdStart = InStr(1, myHL, "&gid=", vbTextCompare)
If gdStart > 0 Then
    gdEnd = InStr(gdStart, myHL, "&p1", vbTextCompare)
    GetGid = Mid(myHL, gdStart + 5, gdEnd - gdStart - 5)
End If
End Function
Put this code in a standard module of your vba project; then return to your worksheet, and in J2 insert this formula:
Excel Formula:
=GetGid(E3)
Copy down as needed

Bye
 
Upvote 0
Would this user-defined function be what you want?

VBA Code:
Function GameID(r As Range) As String
  GameID = Split(Split(r.Hyperlinks(1).Address, "gid=")(1), "&")(0)
End Function

TheWennerWoman.xlsm
EFGHIJ
1
2Won5275015
Extract from hyperlink
Cell Formulas
RangeFormula
J2J2=GameID(E2)
 
Upvote 0
Solution
Thank you both, they both work but I can only mark one as the solution so Peter wins because his is ridiculously short and to the point. Brilliant both of you ?
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,306
Members
449,079
Latest member
juggernaut24

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