Delete all Excel workbooks from a list on worksheet on condition.

U

u473

I need monthly to loop and delete all workbooks listed in column A,
(full path and file name is given) where column B content = "Y"
A B
File Delete
C:\Progress\ProjA.xls Y
C:\Progress\ProjB.xls
F:\Perf /ProjA\Elec.xls
F:\Perf /ProjA\Equip.xls Y
Help appreciated

J.P.
 
D

Don Guillett Excel MVP

I need monthly to loop and delete all workbooks listed in column A,
 (full path and file name is given) where column B content = "Y"
A                                    B
File                            Delete
C:\Progress\ProjA.xls        Y
C:\Progress\ProjB.xls
F:\Perf /ProjA\Elec.xls
F:\Perf /ProjA\Equip.xls     Y
Help appreciated

J.P.

Sub killem()
On Error Resume Next
For Each fn In Range("A2:A22")
If UCase(fn.Offset(, 1)) = "Y" Then Kill fn
End If
Next fn
End Sub
 
U

u473

Brilliant, and thank you again. I was cooking something much more
convoluted.
How would have it been different if path was in Column A, file name in
Column B, Type in Column C and Delete in Column D ?
Sub killem()
On Error Resume Next
For Each fn In Range("A2:A22")
If UCase(fn.Offset(, 4)) = "Y" Then
fn = fn..text + fn.Offset(, 1).text +fn.Offset(, 2).text
Kill fn
End If
Next fn
End Sub
Would t6hat syntax be correct ?
Thank you again,
J.P.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top