copying images from one folder and pasting in another based on schedule in excel file

merQrey

New Member
Joined
Feb 22, 2014
Messages
9
Hi guys
Hope you all well and safe from Covid. while in lockdown im hoping someone can assist me with this query.
i had a macro created whereby image product code is listed in Column A, Column B lists the location of that particular image and Column C displays the location of where i want those images to be copied to. the code for that particular file is listed below. what i need help with if possible is can additional product images codes be listed in the exact same cell separated by ";". herewith the code of the original file

Sub copylistfile()
oldpath = Range("B2")
newpath = Range("C2")
LR = Cells(Rows.Count, "A").End(xlUp).Row
For r = 2 To LR
pc = Cells(r, 1)
fn = Dir(oldpath & pc & ".jpg")
If fn <> "" Then
FileCopy oldpath & pc & ".jpg", newpath & pc & ".jpg"
Cells(r, 4) = "copied"
Else
Cells(r, 4) = "missing"
Cells(r, 4).Interior.ColorIndex = 3
End If
Next
End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Using the split function can get you there. Check out e.g. this tutorial: VBA Split Function – How to Use

Untested code (please, use the VBA tags next time):
VBA Code:
Sub copylistfile()
    Dim pcarr() As String
    oldpath = Range("B2")
    newpath = Range("C2")
    LR = Cells(Rows.Count, "A").End(xlUp).Row
    For R = 2 To LR
        pc = Cells(R, 1)
        pcarr = Split(pc, ";")
        Cells(R, 4).ClearContents
        For p = LBound(pcarr) To UBound(pcarr)
            fn = Dir(oldpath & pcarr(p) & ".jpg")
            If fn <> "" Then
                FileCopy oldpath & pc & ".jpg", newpath & pc & ".jpg"
                Cells(R, 4).Value = Cells(R, 4).Value & "c"
            Else
                Cells(R, 4).Value = Cells(R, 4).Value & "m"
                Cells(R, 4).Interior.ColorIndex = 3
            End If
        Next p
    Next
End Sub
Cheers,
Koen
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,625
Members
449,093
Latest member
catterz66

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