Run time error 13 Type mismatch

TODDLL

New Member
Joined
Apr 7, 2018
Messages
24
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

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
20,120
Office Version
  1. 2016
  2. 2013
  3. 2007
Platform
  1. Windows
Try declaring your variables.
If you have further problems, post the code, rather than a picture, and someone will providing assistance
 

joeu2004

Well-known Member
Joined
Mar 2, 2014
Messages
3,021
Office Version
  1. 2010
Platform
  1. Windows
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:

joeu2004

Well-known Member
Joined
Mar 2, 2014
Messages
3,021
Office Version
  1. 2010
Platform
  1. Windows
(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
 

TODDLL

New Member
Joined
Apr 7, 2018
Messages
24
Office Version
  1. 365
  2. 2010
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!
 

Watch MrExcel Video

Forum statistics

Threads
1,129,483
Messages
5,636,603
Members
416,928
Latest member
ezmeng

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
Top