A sample file would be helpful in this instance, however, you could try something like the below:
Option Explicit
Public Sub StripURL()
Dim strURLVar As String, strTempURL As String
Dim rngURL As Range, rngCell As Range
Dim vURL As Variant
Dim bi As Byte
Set rngURL = Range(Cells(1, "A"), Cells(Rows.Count, "A").End(xlUp))
If Application.CountA(rngURL) Then
strURLVar = Trim(Application.InputBox("Enter Variable to Strip - eg. cid", Type:=2))
If strURLVar <> "False" Then
strURLVar = strURLVar & IIf(Right(strURLVar, 1) <> "=", "=", "")
For Each rngCell In rngURL
If rngCell <> "" Then
vURL = Split(Split(rngCell.Value, "?")(1), "&")
For bi = LBound(vURL) To UBound(vURL)
If UCase(Left$(vURL(bi), Len(strURLVar))) = UCase(strURLVar) Then
If bi > LBound(vURL) Then
strTempURL = "&" & vURL(bi)
Else
strTempURL = IIf(LBound(vURL) = UBound(vURL), "?" & vURL(bi), vURL(bi) & "&")
End If
strTempURL = Replace(rngCell.Value, strTempURL, "")
rngCell.Value = strTempURL
End If
Next bi
End If
Next rngCell
Else
MsgBox "Invalid Criteria - Please Re-Try", vbCritical, "Routine Terminated"
End If
Set rngURL = Nothing
Else
MsgBox "No URLs to Process", vbInformation, "No Data"
End If
End Sub
The above is setup to fire against Column A of the selected sheet -- it will prompt user to enter variable to be stripped (eg cid) ... and will then process the strings in the column and remove the offending variable.
I hope it helps.
(With most VBA - ensure you have a backup of your present data prior to running as you won't be able to "Undo")
Bookmarks