Run time error 13 Type mismatch

TODDLL

New Member
Joined
Apr 7, 2018
Messages
27
Office Version
  1. 365
  2. 2010
I have an Excel table with several columns. In 3 of the columns, I have vba code entered to pop up a msg if a "Y" is entered into the field. Works as it should. However, if I want to delete the row from the table, I get the Runtime error 13. If I delete just the cell with the "Y", no problem. If I try to delete other column fields in that row I receive the error. The data does get deleted, but I get the runtime error. Any way around this? I have also tried clearing the content of the row, but same issue. I have attached the vba code associated with these columns if that would help figure out what to do. Thank you.
 

Attachments

  • Runtime error 13.jpg
    Runtime error 13.jpg
    71.3 KB · Views: 12

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
Try declaring your variables.
If you have further problems, post the code, rather than a picture, and someone will providing assistance
 
Upvote 0
Add:

If Target.Count <> 1 Then Exit Sub

before the Target.Value="Y" line.

PS.... But that means that if the user selects G1:G10, types Y, then presses ctrl+Enter (not ctlr+shift+Enter), your event macro will not display any messages. You could loop when Target.Count > 1 is true. But it is unclear that that is what you want to do when deleting a column or row, notably column G, H or I.
 
Last edited:
Upvote 0
(Sorry, too late to edit....)
PS.... But that means that if the user selects G1:G10, types Y, then presses ctrl+Enter (not ctlr+shift+Enter), your event macro will not display any messages. You could loop when Target.Count > 1 is true. But it is unclear that that is what you want to do when deleting a column or row, notably column G, H or I.
Use the event macro below, and try the following experiment to decide what you want.

1. Select G1:G10, type Y, then press ctrl+Enter to enter Y into the 10 cells all at once.
2. Select G3:G5, right-click and click Delete > Shift Up.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox Target.Count & vbNewLine & Target.Address
End Sub
 
Upvote 0
Michael, thank you for telling me about the XL2BB. I was not aware of this, and will be helpful going forward.
Joeu2004, your code worked perfectly, thank you!
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,873
Members
449,056
Latest member
ruhulaminappu

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