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

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.
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,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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