For example we have a website http://www.amazon.com/Best-Sellers-Books-Architectural-Art-Design/zgbs/books/5005940011/ref=zg_bs_nav_b_2_1 linked to a cell hyperlink in an excel data. From where we need to extract only 5005940011. VBA code for this objective is as follows:
Dim myurl As String
Dim tempval, tempvalnew, nodeid As String
Sub searchVal()
myurl = ActiveCell.Hyperlinks(1).Address
For x = 1 To Len(myurl)
tempval = Mid(myurl, x, 1)
If InStr(tempval, "/") <> 0 Then
counter = counter + 1
End If
If (counter = 6 And tempval <> "/") Then
nodeid = nodeid & tempval
ElseIf counter = 7 Then
ActiveCell.Offset(0, 1).Value = nodeid
nodeid = vbNullString
myurl = vbNullString
Exit Sub
End If
Next x
End Sub
Dim myurl As String
Dim tempval, tempvalnew, nodeid As String
Sub searchVal()
myurl = ActiveCell.Hyperlinks(1).Address
For x = 1 To Len(myurl)
tempval = Mid(myurl, x, 1)
If InStr(tempval, "/") <> 0 Then
counter = counter + 1
End If
If (counter = 6 And tempval <> "/") Then
nodeid = nodeid & tempval
ElseIf counter = 7 Then
ActiveCell.Offset(0, 1).Value = nodeid
nodeid = vbNullString
myurl = vbNullString
Exit Sub
End If
Next x
End Sub