VBA: Find / Replace then add to end of string

Dubyah

New Member
Joined
Mar 30, 2015
Messages
20
Hey guys, I have a large file of links formatted like 'http://www.website.com/page/page/page.html'

Looking for some VBA to clean it up First I need the 'http://www.website.com' removed and replaced with '^' second I need a string added to the end of the link.

Here is what I have for adding text to the end of the string.. Having trouble with the remove and replace.

Code:
Sub add()    Dim c As Range
    For Each c In Selection
        If Not IsNumeric(c) Then
            c.Value = c.Value & "STRING"
        End If
    Next c
End Sub

Feel free to direct me to a page that may help me out.. Looked around and couldn't find what I needed. But maybe I'm searching for the wrong thing..
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Why are you checking for Numeric?
If your values are always in a set place, you can avoid Select as well.

This should work for Column A:

Code:
Sub test()
Dim c As Range
For Each c In Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
    If Left(c, 5) = "http:" Then
        c = Mid(c, InStr(9, c, "/"))
        c = "^" & c & "STRING"
    End If
Next
End Sub
 
Last edited:
Upvote 0
I would use the worksheet function substitute:
Code:
Dim RemoveS, AddS, MyString As String
Dim c As Range

RemoveS = "http://www.website.com/page/page/page.html"
AddS = "^"
MyString = "String"


For Each c In Selection
    If Not IsNumeric(c) Then
        c.Value = WorksheetFunction.Substitute(c.Value, RemoveS, AddS) & MyString
    End If
Next c
 
Upvote 0

Forum statistics

Threads
1,216,105
Messages
6,128,861
Members
449,472
Latest member
ebc9

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