Why do I get "Runtime Error 13 Type Mismatch" when I run this tiny bit of code?

D

drthursday

Sub DeleteNonSubcontracts()
Dim wsheet As Worksheet
For Each wsheet In Worksheets

If wsheet.Range("D10:O10") <> "" Then
Else: wsheet.Delete
End If

Next wsheet


End Sub




Is it not possible to call a range the way I did? This code works fine
if I limit the range to one cell --even if it still pops up all those
nasty "Ok to delete this worksheet" messages.

I would really appreciate any ideas or help.

Best,
Amy
 
J

JE McGimpsey

drthursday said:
Is it not possible to call a range the way I did? This code works fine
if I limit the range to one cell --even if it still pops up all those
nasty "Ok to delete this worksheet" messages.

That's exactly right - you're asking to compare an array (1-row by 12
columns) to a constant (null string).

Try:


Public Sub DeleteNonSubcontracts()
Dim wsheet As Worksheet

On Error Resume Next
Application.DisplayAlerts = False
For Each wSheet In ActiveWorkbook.Worksheets
If Application.CountA(wsheet.Range("D10:O10")) = 0 Then _
wSheet.Delete
Next wSheet
Application.DisplayAlerts = True
End Sub
 

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