On error resume next question

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Hi,
I have the code below in use

All works fine but if i run the code & there are no vales in the cells to be cleared i get a run time error 1004 NO CELLS FOUND

Rich (BB code):
Private Sub ClearSheet_Click()
Dim answer As Integer
 answer = MsgBox("IS IT OK TO DELETE SHEET FIGURES ? ", vbCritical + vbYesNo + vbDefaultButton2, "DLETE WORKSHEET FIGURES MESSAGE")
    If answer = vbNo Then
      Exit Sub
      End If
Range("B1:D1").ClearContents
Range("A34").ClearContents
Sheet12.Range("A3:D29").SpecialCells(xlCellTypeConstants).ClearContents
Range("A3").Select
MsgBox "CELLS HAVE NOW BEEN CLEARED", vbInformation

End Sub

If i put On error resume next after the Private Sub part,

1, Will that stop the error message ?
2, Do i need to add anything else or is On error resume next enough ?

Thanks please advise.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
If i put On error resume next after the Private Sub part,

1, Will that stop the error message ?
Yes, but I would not do that as it could also hide other errors that you might need to know about.

Just add it where needed and turn it off as soon as possible.

Rich (BB code):
Private Sub ClearSheet_Click()
Dim answer As Integer
 answer = MsgBox("IS IT OK TO DELETE SHEET FIGURES ? ", vbCritical + vbYesNo + vbDefaultButton2, "DLETE WORKSHEET FIGURES MESSAGE")
    If answer = vbNo Then
      Exit Sub
      End If
Range("B1:D1").ClearContents
Range("A34").ClearContents
On Error Resume Next
Sheet12.Range("A3:D29").SpecialCells(xlCellTypeConstants).ClearContents
On Error GoTo 0
Range("A3").Select
MsgBox "CELLS HAVE NOW BEEN CLEARED", vbInformation

End Sub
 
Upvote 0
Morning,
I have done what you advised thanks & it still has an issue on one worksheet.

I applied the code to the existing code thus below now in use.

Rich (BB code):
Private Sub ClearSheet_Click()
Dim answer As Integer
 answer = MsgBox("IS IT OK TO DELETE SHEET FIGURES ? ", vbCritical + vbYesNo + vbDefaultButton2, "DLETE WORKSHEET FIGURES MESSAGE")
    If answer = vbNo Then
      Exit Sub
      End If
Range("B1:D1").ClearContents
Range("A34").ClearContents
On Error Resume Next
Sheet12.Range("A3:D29").SpecialCells(xlCellTypeConstants).ClearContents
On Error GoTo 0
Range("A3").Select
MsgBox "CELLS HAVE NOW BEEN CLEARED", vbInformation

End Sub

After i click OK to the message CELLS HAVE NOW BEEN CLEARED i see a run time error message 13 Mismatch
When i debug the following code is shown in yellow.

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)


If Not Intersect(Target, Range("D3:D29")) Is Nothing Then

On Error Resume Next
If UCase(Target.Value) = "L" Then Target.Value = "4"
If UCase(Target.Value) = "W" Then Target.Value = "5"
If UCase(Target.Value) = "B" Then Target.Value = "6"
If UCase(Target.Value) = "C" Then Target.Value = "7"
On Error GoTo 0

End If
    If Not (Application.Intersect(Target, Range("A2:D29")) _
      Is Nothing) Then
        With Target
            If Not .HasFormula Then
                Application.EnableEvents = False
                .Value = UCase(.Value)
                Application.EnableEvents = True
            End If
        End With
    End If

End Sub

When using the worksheet in column D range i would enter L, W, B or C to the apply the value to the cell 4,5,6 & 7

This part runs as its a change event so how can i stop it showing the error message.

I did try the same approach as above which didnt show the message but then just put the numerical value in cells A,B,C & D
Thanks
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,853
Members
449,051
Latest member
excelquestion515

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