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.

http://eworld.com/first/http://eworld.com/first/
https://pacbell.com/https://pacbell.com/
MW http://intranet/solar/ (external)http://intranet/solar/
https://mbos.google.com
(internal link)
https://mbos.google.com
N/A
External link is http://mynah.sbc.com (outside)http://mynah.sbc.com
NOT VALID
1 PROD
2 TEST http://www.text.com
http://www.text.com
ERROR

<tbody>
</tbody>
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
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,214,950
Messages
6,122,428
Members
449,083
Latest member
Ava19

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