delete old files from, folder and list, shift cells up under conditions.

BRB1983

Board Regular
Joined
Aug 29, 2019
Messages
61
the issue is that the code is is deleting more than i ask for. it also deletes a cell that is not colored.

Code:
Sub delete_test_2()
Dim MyFolder As String
Dim cell As Range
Application.ScreenUpdating = False
    With Sheets("Delete Revs")
    MyFolder = .Range("K1").Value & "\"
        For Each cell In .Range("C3:C17")
            If cell.Interior.Color = RGB(255, 255, 255) And cell.Offset(0, 1) = "A" Then
                Kill MyFolder & cell.Value & ".pdf"
                cell.Offset(0, 1).Delete xlShiftUp
                cell.Offset(0, 2).Delete xlShiftUp
                cell.Delete xlShiftUp
            End If
        Next cell
            For Each cell In .Range("C3:C17")
                If cell.Interior.Color = RGB(255, 255, 255) And cell.Offset(0, 1) = "0" Then
                    Kill MyFolder & cell.Value & ".pdf"
                    cell.Offset(0, 1).Delete xlShiftUp
                    cell.Offset(0, 2).Delete xlShiftUp
                    cell.Delete xlShiftUp
                End If
            Next cell
 
Last edited by a moderator:
i found an alternative route that works but it gives me "file not found " when code completes.
i think it is searching a blank cell. any ideas? code:
Code:
Dim MyFolder As StringApplication.ScreenUpdating = False
    With Sheets("Delete Revs")
        MyFolder = .Range("K1").Value & "\"
            For Each cell In Range("L2:L10000")
            If cell = "" Then
            Else
               Kill MyFolder & cell.Value & ".pdf"
              End If
            Next
    End With
Application.ScreenUpdating = True
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
That should ignore blank cells. What is the value of Cell when it fails?
 
Upvote 0
Glad it's sorted & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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