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.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Trap the error using an error handler, open message box then Exit Sub.
If you want an actual example, you need to provide the rest of the code and the error number and message you're getting because that is too general.
Please enclose your procedure in code tags (see vba button on posting toolbar).
 
Upvote 0
Trap the error using an error handler, open message box then Exit Sub.
If you want an actual example, you need to provide the rest of the code and the error number and message you're getting because that is too general.
Please enclose your procedure in code tags (see vba button on posting toolbar).
The part of code that is in blue text is where the error occurs in VBA.


[Private Sub CommandButton1_Click()

ActiveSheet.Unprotect
Range("BJ87:BM110").ClearContents
Range("A14:F14").Select
Range("dump_table").ClearContents
Range("ch12").Select
ActiveSheet.PasteSpecial Format:="Unicode Text", Link:=False, _
DisplayAsIcon:=False, NoHTMLFormatting:=True


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
End Sub][/CODE]
 
Upvote 0
you need to provide the rest of the code and the error number and message you're getting

Please enclose your procedure in code tags (see vba button on posting toolbar).
Well, you did neither, but I'll try anyway.
VBA Code:
[Private Sub CommandButton1_Click()

On Error GoTo errHandler

your code

activesheet.protect 'after this line add the next 9 lines
exitHere:
Exit Sub

errHandler:
If err.Number = (put the error number here) Then
  Msgbox "your message here"
Else
  Msgbox "Error " & err.Number & ": " & err.Description
End If
Resume exitHere

End Sub
I'm guessing user should have manually copied something to the clipboard before running this so I guess all you can do is trap the error rather than check for a missing value.
 
Upvote 0
Well, you did neither, but I'll try anyway.
VBA Code:
[Private Sub CommandButton1_Click()

On Error GoTo errHandler

your code

activesheet.protect 'after this line add the next 9 lines
exitHere:
Exit Sub

errHandler:
If err.Number = (put the error number here) Then
  Msgbox "your message here"
Else
  Msgbox "Error " & err.Number & ": " & err.Description
End If
Resume exitHere

End Sub
I'm guessing user should have manually copied something to the clipboard before running this so I guess all you can do is trap the error rather than check for a missing value.
 
Upvote 0
Sorry for not being a little more detailed.
The user is copying data from an data capturing app designed in visio. He just right clicks anywhere in the data window and then switches to my excel workbook and pastes into spreadsheet. If he forgets to copy that data and there happens to be excel data leftover in the clipboard he will get a 1004 error error code.

I tried your suggestion but come with the error.
 
Upvote 0
VBA Code:
Private Sub CommandButton1_Click()

ActiveSheet.Unprotect
Range("BJ87:BM110").ClearContents
Range("A14:F14").Select
Range("dump_table").ClearContents
Range("ch12").Select
ActiveSheet.PasteSpecial Format:="Unicode Text", Link:=False, _
DisplayAsIcon:=False, NoHTMLFormatting:=True

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
End Sub
 
Upvote 0
Well, post 7 doesn't contain what I showed you so I can't help with a suggestion if I can't see how it was implemented.
 
Upvote 0
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
ActiveSheet.PasteSpecial Format:="Unicode Text", Link:=False, _
DisplayAsIcon:=False, NoHTMLFormatting:=True

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
exitHere:
Exit Sub

errHandler:
If err.Number = (put the error number here) Then
  Msgbox "your message here"
Else
  Msgbox "Error " & err.Number & ": " & err.Description
End If
Resume exitHere
End Sub
 
Upvote 0
If err.Number = (put the error number here) Then

When I wrote that you had not yet revealed the error number. You were supposed to enter it where it says "(put the error number here). Maybe it should be
If Err.Number = 1004 Then :unsure:

No parentheses around the number.
 
Upvote 0

Forum statistics

Threads
1,215,161
Messages
6,123,378
Members
449,097
Latest member
Jabe

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