VBA Replace Based on Data from Cells in Another Column

tomgrandy

New Member
Joined
May 10, 2024
Messages
28
Office Version
  1. 365
Platform
  1. MacOS
In the image below, I am trying to write a macro that will replace the ~ symbol in the path in Columns C, D, E & F with the Value in Column A (see image)


1​
images/~.jpgimages/~_2.jpgimages/~_3.jpgimages/~_4.jpg
2​
images/~.jpgimages/~_2.jpgimages/~_3.jpgimages/~_4.jpg
3​
images/~.jpgimages/~_2.jpgimages/~_3.jpgimages/~_4.jpg
4​
images/~.jpgimages/~_2.jpgimages/~_3.jpgimages/~_4.jpg
5​
images/~.jpgimages/~_2.jpgimages/~_3.jpgimages/~_4.jpg
7​
images/~.jpgimages/~_2.jpgimages/~_3.jpgimages/~_4.jpg
8​
images/~.jpgimages/~_2.jpgimages/~_3.jpgimages/~_4.jpg
9​
images/~.jpgimages/~_2.jpgimages/~_3.jpgimages/~_4.jpg
10​
images/~.jpgimages/~_2.jpgimages/~_3.jpgimages/~_4.jpg


This will have to move through approximately 450 items so that the last row would look something like this:

images/450.jpgimages/450_2.jpgimages/450_3.jpgimages/450_4.jpg

Any help would be appreciated!

Thanks!
Tom
 

Attachments

  • Screenshot 2024-06-07 at 8.22.05 PM.png
    Screenshot 2024-06-07 at 8.22.05 PM.png
    83 KB · Views: 22

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
VBA Code:
Sub AAA()
    Dim lRow As Long
    Dim vA As Variant
    Dim vB As Variant
    Dim i As Long
    Dim j As Long
    
    lRow = Cells(Rows.Count, "A").End(xlUp).Row
    
    vA = Range("A1").Resize(lRow).Value
    vB = Range("C1").Resize(lRow, 4).Value
    
    For i = 1 To UBound(vA)
        For j = 1 To UBound(vB, 2)
            vB(i, j) = Replace(vB(i, j), "~", vA(i, 1))
        Next j
    Next i
    
    Range("C1").Resize(UBound(vB), UBound(vB, 2)).Value = vB
End Sub

Artik
 
Upvote 0

Forum statistics

Threads
1,221,624
Messages
6,160,904
Members
451,675
Latest member
Assy Bissy

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