How to remove image dimensions from urls that are in a Excel Column?

brvnbld

New Member
Joined
Jun 29, 2022
Messages
16
Office Version
  1. 2021
Platform
  1. Windows
Hi there, I have a long list of Image urls in a column all which have image dimensions, for example https://example.com/wp-content/uploads/2022/07/sample-image-300x212.jpg . I need to remove everything that dimensions 300x212, these dimensions vary. I thought I can replace this -*x, with x and then x*. so that all those get deleted. But the replace sees the first "-", so it didn't work. The image urls also have other extensions like webp etc.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
You can use the InstrRev function to search in reverse...

VBA Code:
    Dim url As String
    url = "https://example.com/wp-content/uploads/2022/07/sample-image-300x212.jpg"
   
    url = Left(url, InStrRev(url, "-") - 1) & Mid(url, InStrRev(url, ".jpg"))
   
    MsgBox url, vbInformation 'for demenstration purposes

So in this example the message box will display...

VBA Code:
https://example.com/wp-content/uploads/2022/07/sample-image.jpg

Hope this helps!
 
Upvote 0
People like you are making Internet a better place. I am so happy I found this forum. Thanks again.
 
Upvote 0
I have to say, that's great to hear. Yes, this is a great place to learn.

By the way, give me a minute, I just want make another suggestion. Actually, I should have made it originally.
 
Upvote 0
Just in case you may have images with different file extensions, other than .jpg, you can replace...

VBA Code:
url = Left(url, InStrRev(url, "-") - 1) & Mid(url, InStrRev(url, ".jpg"))

with

VBA Code:
url = Left(url, InStrRev(url, "-") - 1) & Mid(url, InStrRev(url, "."))

So this will search for a period ( . ), instead of .jpg.
 
Upvote 0
Just in case you may have images with different file extensions, other than .jpg, you can replace...

VBA Code:
url = Left(url, InStrRev(url, "-") - 1) & Mid(url, InStrRev(url, ".jpg"))

with

VBA Code:
url = Left(url, InStrRev(url, "-") - 1) & Mid(url, InStrRev(url, "."))

So this will search for a period ( . ), instead of .jpg.
Yeah, but that will also replace the values after example. com too,. yes?
 
Upvote 0
Oh, yes that's right.

So, in that case, you may want to first check for the extension...

VBA Code:
If LCase(Right(url, 4)) = ".jpg" Then

And then, if true, remove the dimensions from the string...

VBA Code:
url = Left(url, InStrRev(url, "-") - 1) & ".jpg"

And, of course, you could check for more than one type of file extension, and if found you would search for the period instead of ".jpg" or what have you.
 
Upvote 0
or We could do this?

Dim url As String
url = "https://example.com/wp-content/uploads/2022/07/sample-image-300x212.jpg"
url = Left(url, InStrRev(url, "-") - 1) & Mid(url, InStrRev(url, ".webp"))
url = Left(url, InStrRev(url, "-") - 1) & Mid(url, InStrRev(url, ".jpg"))
url = Left(url, InStrRev(url, "-") - 1) & Mid(url, InStrRev(url, ".png"))

Since the files might be from one of the extensions, only one of the lines will get executed,. yes?
 
Upvote 0

Forum statistics

Threads
1,224,815
Messages
6,181,135
Members
453,021
Latest member
Justyna P

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