Help with Kill Range Problem

SDJ98

New Member
Joined
Apr 21, 2011
Messages
27
Hi,

First off, I want to say that I love this board and it has helped me so many times in the past, but I had to sign up and ask this question which I couldn't find from searching. I'm a VBA idiot, but I'm trying to modify some code (Excel 2003).

The macro is intended to go through a specified list of directory paths to folders, which begin in cell B10 and continue on for 40 or so lines. Its supposed to delete all the files out of these folders. The problem is that not every folder has stuff in it every month, so when this macro comes to that folder, it bombs out and stops. What I want it to do is just ignore that folder and continue. In other words I want the macro to say "if theres stuff in this folder, delete it, then move on to the next folder. If there isn't stuff in that folder, fine, just move on to the next folder"

Macro in question:


Sub Button1_Click()

Range("b10").Select
Do Until ActiveCell.Value = ""
Selection.Copy
Sheets("Directory").Select
Range("b2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Kill Range("Direct") & "*"
Sheets("Rules").Select
ActiveCell.Offset(1, 0).Select
Loop
'
End Sub

For what its worth, I didn't write the macro, nor do I really know how to. I'm trying to learn them by modifying.

Really appreciate the help.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
The thing is that these folders do exist. Its just that some of them are empty.

When the macro stops it highlights the:

Kill Range ("Direct") & "*"

portion of the macro.
 
Upvote 0
this is so basic that I feel stupid asking, but what/where is the appropriate place to insert that into the macro.

I'll try your way although I keep finding references to "On Error Resume Next", which might do the trick too?

ETA: Situation resolved. On error resume next worked in this situation and I believe its appropriate. Thanks for the help.
 
Last edited:
Upvote 0
Try:

Code:
If Len(Dir(Range("Direct") & "*")) > 0 Then
    Kill Range("Direct") & "*"
End If

On Error Resume Next is also a reasonable solution.
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,787
Members
452,942
Latest member
VijayNewtoExcel

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