run Time Errors in worksheet with VB Code

vze

New Member
Joined
Apr 7, 2022
Messages
9
Office Version
  1. 365
Platform
  1. Windows
I have two dependent drop down lists.
Column J populates based on the selection of Column I.

Scenario
1. I select a value in both Column I and J but then change my mind and want to replace the column I value, I want column J to be cleared. Formula 1 does this.
2. If Column I is blank, Column J should be blank. 2nd formula does this.

Issue is if I try to select all rows in this excel and delete them I get run time 13.
If I try to enter values in the other regular text cells and tab or move to another cell I get run time 1004.

How do I prevent these run time errors because they turn off all validations.

I have some headers locked but the sheet is not protected. So not sure why this happens
 

Attachments

  • image.png
    image.png
    53.7 KB · Views: 12

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Your code is very likely to cause excel to crash, this is because it goes into a loop. You should turn of events BEFORE you write anything to the worksheet , otherwise the action of writing to the worksheet will cause the same subroutine to be called again and again and again forever or until some error cause it to crash. so just move this line of code
VBA Code:
Application.EnableEvents =False
to just before the first if statement
Can I say the saving the workbook every time you make any change to the worksheet is likely to make the workbook very slow and tedious to work with. Even if you are saving to an SSD drive is will still be slow. Not recommended
 
Upvote 0
ok that didnt work, I still get run time errors. Is there another way to achieve the result in red in the attached screenshot. Basically I want the row in column Sub Root cause to reset each time a selection is made under Root Cause AND if Root Cause is deleted to a blank I want Sub Root Cause = blank

The vb code in original post works for these columns but causes run time errors on other columns when making selections, moving cells or deleting data in the other cells.
 

Attachments

  • NEW IMAGE.png
    NEW IMAGE.png
    144.8 KB · Views: 8
Upvote 0
The code you posted in post#3 will cause errors YOU MUST PUT
VBA Code:
Application.EnableEvents =False
at the top of the module
and
VBA Code:
Application.EnableEvents =TRUE
at the bottom.
ther is no point in lookingfor other errors until you have done that!!
 
Upvote 0
The code you posted in post#3 will cause errors YOU MUST PUT
VBA Code:
Application.EnableEvents =False
at the top of the module
and
VBA Code:
Application.EnableEvents =TRUE
at the bottom.
ther is no point in lookingfor other errors until you have done that!!
so I did in fact do this even before posting the original question. The same errors occur either way. Same run time errors I posted above.
 

Attachments

  • updated.png
    updated.png
    33.1 KB · Views: 6
Upvote 0
I think your probelm might be because you are checking validation.type on cells that don't have validation. so try this modification:
VBA Code:
If Target.column = 9 then
 If target.validation.type=3 then
  target.offset(0,1).value=""
 end if
end if
 
Upvote 0
Solution
I think your probelm might be because you are checking validation.type on cells that don't have validation. so try this modification:
VBA Code:
If Target.column = 9 then
 If target.validation.type=3 then
  target.offset(0,1).value=""
 end if
end if
Thanks I think this has worked. I did this with the 2nd part of the code as well and it seems to be working. Thanks so much!
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,749
Members
448,989
Latest member
mariah3

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