VBA Find and Replace Part of a URL

tomgrandy

New Member
Joined
May 10, 2024
Messages
41
Office Version
  1. 365
Platform
  1. MacOS
Here is my dilemma that might seem easy to you all, but am unsure how to write a VBA to accomplish.

I have a cell that I need to do a find and replace on up to the very last part (/1.jpg, /2.jpg, etc.)

The original cell info is as follows:

/1.jpg

What I need it to do when the VBA runs is rename it to (URL and path in blue to identify what needs replaced.

sites/default/files/images/auctions/AUCTION_DATE/1.jpg
sites/default/files/images/auctions/AUCTION_DATE/2.jpg
sites/default/files/images/auctions/AUCTION_DATE/3.jpg

Thanks in advance!
 
Another option to try:
VBA Code:
Sub tomgrandy_1()
Dim i As Long
Dim c As Range
Dim tx As String
Dim va, ary

va = Range("A1", Cells(Rows.Count, "A").End(xlUp))
tx = "sites/default/files/images/auctions/AUCTION_DATE/"
For i = 1 To UBound(va, 1)
    ary = Split(va(i, 1), "/")
    va(i, 1) = tx & ary(UBound(ary))
Next
Range("B1").Resize(UBound(va, 1), 1) = va
End Sub
Example:
Book1
AB
1https://images.sitename.com/AuctionImages/3173/239780/FullSize/1.jpgsites/default/files/images/auctions/AUCTION_DATE/1.jpg
2https://images.sitename.com/AuctionImages/3173/239780/FullSize/2.jpgsites/default/files/images/auctions/AUCTION_DATE/2.jpg
3https://images.sitename.com/AuctionImages/1111/239780/FullSize/3.jpgsites/default/files/images/auctions/AUCTION_DATE/3.jpg
4https://images.sitename.com/AuctionImages/3333/222222/FullSize/4.jpgsites/default/files/images/auctions/AUCTION_DATE/4.jpg
Sheet4
@Akuini - Thanks for the solution!! Works impressively well. Much appreciated.
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
You're welcome, glad to help & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,223,883
Messages
6,175,167
Members
452,615
Latest member
bogeys2birdies

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