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.
 
Actually, I think you'll run into problems with it. Try something like this instead...

VBA Code:
    Dim url As String
    url = "https://example.com/wp-content/uploads/2022/07/sample-image-300x212.jpg"
   
    Dim exts As Variant
    exts = Array(".webp", ".jpg", ".png")
   
    Dim isImage As Boolean
    isImage = False
   
    Dim i As Long
    For i = LBound(exts) To UBound(exts)
        If LCase(url) Like LCase("*-###x###" & exts(i)) Then 'compare using search pattern
            url = Left(url, InStrRev(url, "-") - 1) & exts(i)
            isImage = True
            Exit For
        End If
    Next i

    If isImage = True Then
        MsgBox url, vbInformation
    Else
        MsgBox "No image file name found!", vbExclamation
    End If
 
Upvote 0
Solution

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,214,394
Messages
6,119,263
Members
448,881
Latest member
Faxgirl

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