Need Macro vba to extract only URL string from a column having strings with some text plus URL

mypunit

New Member
Joined
Nov 6, 2014
Messages
1
Hello Experts. I just started learning about VBA and got below problem. In below example, column A is a huge set of cells that has strings with URLs in it. I need to extract only URL starting from "http" keyword. There are no cases when this string has more than one URL.

I searched internet and found following formula somehow working for me, however I could never figure out how to get VBA macro for this purpose.
B1=MID(A1,FIND("http",A1),IFERROR(FIND(" ",A1,FIND("http",A1))-1,LEN(A1))-FIND("http",A1)+1)
I request you to please help me out here. I would be sincerely thankful.

IMPORTANT: In final VBA solution, I need a VBA which can just remove extra text from COLUMN A and leaves the URL string in COLUMN A itself. I dont want to copy it to anywhere else.

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]http://eworld.com/first/[/TD]
[TD]http://eworld.com/first/[/TD]
[/TR]
[TR]
[TD]https://pacbell.com/[/TD]
[TD]https://pacbell.com/[/TD]
[/TR]
[TR]
[TD]MW http://intranet/solar/ (external)[/TD]
[TD]http://intranet/solar/[/TD]
[/TR]
[TR]
[TD]https://mbos.google.com
(internal link)[/TD]
[TD]https://mbos.google.com[/TD]
[/TR]
[TR]
[TD]N/A[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]External link is http://mynah.sbc.com (outside)[/TD]
[TD]http://mynah.sbc.com[/TD]
[/TR]
[TR]
[TD]NOT VALID[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1 PROD
2 TEST http://www.text.com[/TD]
[TD]http://www.text.com[/TD]
[/TR]
[TR]
[TD]ERROR[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hello,

is this adequate?

Code:
Sub GET_URL()
    Application.ScreenUpdating = False
    Range(Cells(1, 1), Cells(ActiveSheet.UsedRange.Rows.Count, 1)).Select
    Selection.Replace What:="*http", Replacement:="http", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False
    Selection.Replace What:="(*", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False
    Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False
    For MY_ROWS = 1 To ActiveSheet.UsedRange.Rows.Count
        If Left(Range("A" & MY_ROWS).Value, 2) <> "ht" Then
            Range("A" & MY_ROWS).ClearContents
        End If
    Next MY_ROWS
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Code:
Sub M_snb()
    sn = Cells(1).CurrentRegion.resize(,2)
    
    For j = 1 To UBound(sn)
        st = Filter(Split(sn(j, 1)), "://")
        sn(j, 2) = ""
        If UBound(st) > -1 Then sn(j, 2) = st(0)
    Next
    
    Cells(1).CurrentRegion.resize(,2) = sn
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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