if file name in column C is red the delete that file from folder

BRB1983

Board Regular
Joined
Aug 29, 2019
Messages
61
I am trying to delete old files from a folder. file names are in column C and old files are colored RGB(255,0,0) i get an error when running this code." file not found". i tried peacing different codes together but, i'm still learning.

Code:
Sub Delete_test()
Dim MyFolder As String
Dim MyFile As String
Dim cell As Variant
Dim source As Range
Set source = Range("c3:c8")
MyFolder = Sheets("Delete Revs").Range("K1").Value & "\"
MyFile = Dir(MyFolder & "\" & "*.pdf*")
    For Each cell In source
        If cell.Interior.Color = RGB(255, 0, 0) Then
            Kill MyFile
        Else
        End If
    Next
End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Do the file names include the file path and/or the file extension?
 
Upvote 0
Ok, how about
Code:
Sub BRB1983()
   Dim MyFolder As String
   Dim cell As Range
   
   With Sheets("Delete Revs")
      MyFolder = .Range("K1").Value & "\"
      For Each cell In .Range("C3:C8")
        If cell.Interior.Color = RGB(255, 0, 0) Then
           Kill MyFolder & cell.Value & ".pdf"
        End If
      Next cell
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
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