Error

obiwann

Board Regular
Joined
Jan 2, 2014
Messages
142
I have a Macro that will show an error at a specific point in the Macro.
ActiveSheet.PasteSpecial Format:="Unicode Text", Link:=False, _
DisplayAsIcon:=False, NoHTMLFormatting:=True
If this error appears, I want a message box saying "You forgot to Copy Raw Prove Data" and then stop the Macro from running.
 
It is still giving me the same error, see yellow test

VBA Code:
Private Sub CommandButton1_Click()
On Error GoTo errHandler
ActiveSheet.Unprotect
Range("BJ87:BM110").ClearContents
Range("A14:F14").Select
Range("dump_table").ClearContents
Range("ch12").Select
[COLOR=rgb(250, 197, 28)]ActiveSheet.PasteSpecial Format:="Unicode Text", Link:=False, _
DisplayAsIcon:=False, NoHTMLFormatting:=True[/COLOR]

Range("ch12").Select

If Range("A14") <> "" Then
If MsgBox("There is Data already present, do you want to overwrite", vbYesNo) = vbNo Then Exit Sub
End If

'Temperature Data
Range("BJ87").value = Range("db3")
Range("BJ88").value = Range("db4")
Range("BJ89").value = Range("db5")
Range("BJ90").value = Range("db6")


ActiveSheet.Protect
exitHere:
Exit Sub

errHandler:
If Err.Number = 1004 Then
  MsgBox "You Forgot to Copy Raw Proving Data"
Else
  MsgBox "Error " & Err.Number & ": " & Err.Description
End If
Resume exitHere
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
I see no yellow text. And the error number you get is 1004?
 
Upvote 0
I see no yellow text. And the error number you get is 1004?
For some reason when Highlighted the section of code that was highlighted in yellow generated some extra code around the error. And yes the error is 1004
 
Upvote 0
Typically, you indicate like so

VBA Code:
Range("BJ87").value = Range("db3") '<< error 1004 is raised at this line

Obviously you use the right line, not the one I used as an example. Note the preceding single quote ( " ) - allows you to have it in your code without messing it up.
 
Upvote 0
Typically, you indicate like so

VBA Code:
Range("BJ87").value = Range("db3") '<< error 1004 is raised at this line

Obviously you use the right line, not the one I used as an example. Note the preceding single quote ( " ) - allows you to have it in your code without messing it up.
I am confused now. Can you copy all my code and insert your code?
 
Upvote 0
Ok, here is a simple macro where I get the same error. Can you please modify with your code so I can test it?

VBA Code:
Sub Macro1()

    Range("A1").Select
    Selection.Copy
    Range("B1").Select
    
ActiveSheet.PasteSpecial Format:="Unicode Text", Link:=False, _
DisplayAsIcon:=False, NoHTMLFormatting:=True

End Sub
 
Upvote 0
Perhaps you're after something like the code below. See whether this helps.

VBA Code:
Private Sub CommandButton1_Click()

    ActiveSheet.Unprotect
    Range("BJ87:BM110").ClearContents
    Range("A14:F14").Select
    Range("dump_table").ClearContents
    Range("ch12").Select
    
    On Error Resume Next
    Dim LastErr As Long
    ActiveSheet.PasteSpecial Format:="Unicode Text", Link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=True
    LastErr = VBA.Err.Number
    Err.Clear
    On Error GoTo 0
    
    If LastErr = 0 Then
        
        Range("ch12").Select
        If Range("A14") <> "" Then
            If MsgBox("There is Data already present, do you want to overwrite", vbYesNo) = vbNo Then Exit Sub
        End If
        
        'Temperature Data
        Range("BJ87").Value = Range("db3")
        Range("BJ88").Value = Range("db4")
        Range("BJ89").Value = Range("db5")
        Range("BJ90").Value = Range("db6")
        
        End With
        ActiveSheet.Protect
    
    Else
        MsgBox "You forgot to Copy Raw Prove Data", vbExclamation
    End If
End Sub
 
Upvote 0
Perhaps you're after something like the code below. See whether this helps.

VBA Code:
Private Sub CommandButton1_Click()

    ActiveSheet.Unprotect
    Range("BJ87:BM110").ClearContents
    Range("A14:F14").Select
    Range("dump_table").ClearContents
    Range("ch12").Select
   
    On Error Resume Next
    Dim LastErr As Long
    ActiveSheet.PasteSpecial Format:="Unicode Text", Link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=True
    LastErr = VBA.Err.Number
    Err.Clear
    On Error GoTo 0
   
    If LastErr = 0 Then
       
        Range("ch12").Select
        If Range("A14") <> "" Then
            If MsgBox("There is Data already present, do you want to overwrite", vbYesNo) = vbNo Then Exit Sub
        End If
       
        'Temperature Data
        Range("BJ87").Value = Range("db3")
        Range("BJ88").Value = Range("db4")
        Range("BJ89").Value = Range("db5")
        Range("BJ90").Value = Range("db6")
       
        End With
        ActiveSheet.Protect
   
    Else
        MsgBox "You forgot to Copy Raw Prove Data", vbExclamation
    End If
End Sub
 
Upvote 0
It still gets stuck on error code 1004
If that's te case, on what line?

The error will continue to occur conditionally, but the suggested code ignores that error and produces a message as per your request:
If this error appears, I want a message box saying "You forgot to Copy Raw Prove Data" and then stop the Macro from running.

I had to get rid of the End With
... as per your original code from post #3.
I only amended the part of your code concerning your query.
 
Upvote 0

Forum statistics

Threads
1,215,671
Messages
6,126,133
Members
449,294
Latest member
Jitesh_Sharma

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