Rewrite Multiple Items in Spreadsheet

tomgrandy

New Member
Joined
May 10, 2024
Messages
41
Office Version
  1. 365
Platform
  1. MacOS
I have a spreadsheet with multiple columns that copy the value in column L (Path_to_Primary_Image)

I need to rewrite those .jpg values in the Image_2, Image_3, and Image_4 columns to be

Image_2 = 1_1.jpg
Image_3 = 1_2.jpg
Image_4 = 1_3.jpg

And continue that renaming down the each of those three columns so

Path to Primary Image of 2.jpg would be renamed to:

Image_2 = 2_1.jpg
Image_3 = 2_2.jpg
Image_4 = 2_3.jpg

This would continue down each of the three columns until ALL 8.jpg have been renamed.

As always, your help is much appreciated.

Path_to_Primary_ImagePath_to_Image_2Path_to_Image_3Path_to_Image_4
sites/default/files/images/auctions/AUCTION_DATE/1.jpgsites/default/files/images/auctions/AUCTION_DATE/1.jpgsites/default/files/images/auctions/AUCTION_DATE/1.jpgsites/default/files/images/auctions/AUCTION_DATE/1.jpg
sites/default/files/images/auctions/AUCTION_DATE/2.jpgsites/default/files/images/auctions/AUCTION_DATE/2.jpgsites/default/files/images/auctions/AUCTION_DATE/2.jpgsites/default/files/images/auctions/AUCTION_DATE/2.jpg
sites/default/files/images/auctions/AUCTION_DATE/3.jpgsites/default/files/images/auctions/AUCTION_DATE/3.jpgsites/default/files/images/auctions/AUCTION_DATE/3.jpgsites/default/files/images/auctions/AUCTION_DATE/3.jpg
sites/default/files/images/auctions/AUCTION_DATE/4.jpgsites/default/files/images/auctions/AUCTION_DATE/4.jpgsites/default/files/images/auctions/AUCTION_DATE/4.jpgsites/default/files/images/auctions/AUCTION_DATE/4.jpg
sites/default/files/images/auctions/AUCTION_DATE/5.jpgsites/default/files/images/auctions/AUCTION_DATE/5.jpgsites/default/files/images/auctions/AUCTION_DATE/5.jpgsites/default/files/images/auctions/AUCTION_DATE/5.jpg
sites/default/files/images/auctions/AUCTION_DATE/7.jpgsites/default/files/images/auctions/AUCTION_DATE/7.jpgsites/default/files/images/auctions/AUCTION_DATE/7.jpgsites/default/files/images/auctions/AUCTION_DATE/7.jpg
sites/default/files/images/auctions/AUCTION_DATE/8.jpgsites/default/files/images/auctions/AUCTION_DATE/8.jpgsites/default/files/images/auctions/AUCTION_DATE/8.jpgsites/default/files/images/auctions/AUCTION_DATE/8.jpg
sites/default/files/images/auctions/AUCTION_DATE/9.jpgsites/default/files/images/auctions/AUCTION_DATE/9.jpgsites/default/files/images/auctions/AUCTION_DATE/9.jpgsites/default/files/images/auctions/AUCTION_DATE/9.jpg
sites/default/files/images/auctions/AUCTION_DATE/10.jpgsites/default/files/images/auctions/AUCTION_DATE/10.jpgsites/default/files/images/auctions/AUCTION_DATE/10.jpgsites/default/files/images/auctions/AUCTION_DATE/10.jpg
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Tried the following but debug showed that:

"If InStr(1, Cells(r, "M"), ".jpg") > 0 Then":" was the problem.

VBA Code:
Sub ReplaceChangeSecondaryImageJPGs()

    Dim lr As Long
    Dim r As Long
    
    Application.ScreenUpdating = False

    
'   Loop through all rows starting with row 3

'       Check to see if column M value has ".jpg" in it
        If InStr(1, Cells(r, "M"), ".jpg") > 0 Then
'           Replace value with column M
            Cells(r, "M").Value = Replace(Cells(r, "M").Value, ".jpg", Format(Cells(r, "M"), "_1.jpg"))

    End If
    
    
    Application.ScreenUpdating = True
    
    MsgBox "Image 2 Rewrite Complete!"
    
End Sub
 
Upvote 0
Tried a simpler method, but it did not change ".jpg" to "_1.jpg" though I did not get an error:

VBA Code:
Sub modChangeSecondaryImageJPGs()

    Application.ScreenUpdating = False

    Columns("M").Replace What:=".jpg ", _
                            Replacement:="_1.jpg", _
                            LookAt:=xlPart, _
                            SearchOrder:=xlByRows, _
                            MatchCase:=False, _
                            SearchFormat:=False, _
                            ReplaceFormat:=False
                            
                                
    Application.ScreenUpdating = True
    
    MsgBox "Secondary Image Rewrite Complete!"
    
    
End Sub
 
Upvote 0
This worked:

VBA Code:
Sub modChangeSecondaryImageJPGs()

Range("M2:M70000").Replace What:=".jpg", Replacement:="_1.jpg"

Range("N2:N70000").Replace What:=".jpg", Replacement:="_2.jpg"

Range("O2:O70000").Replace What:=".jpg", Replacement:="_3.jpg"

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,883
Messages
6,175,168
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