Macro / VBA not working

Excelquestion35

New Member
Joined
Nov 29, 2021
Messages
35
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

For the first time I tried creating my own VBA code to assist my worksheet. I had the issue that the cells of dependent drop down lists retained their value while their parent was changed.
I have looked up multiple types of code that seem to solve this question, by using VBA. All methods did not work in the workbook, but should normally resolve my question.
I also tried downloading a prescripted version but even this workbook did not seem to work.

This seems to me that I stumbled upon a new problem, but I'm lost. How can I check whether my Macros are enabledf (I do not have a yellow bar saying macros are disabled) and should work properly? And if the code is working properly?

Thanks in advance
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
14,991
Office Version
  1. 365
Platform
  1. Windows
Try running one and see if anything happens.

If you're using events (worksheet change for example) then enter the Stop command just below the Sub line and carry out whatever action should cause the code to fire. If the code is working then it will enter debug mode and have a yellow bar through the Stop command when you switch to the editor.
 

SQUIDD

Well-known Member
Joined
Jan 2, 2009
Messages
2,038
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi

excel 2019 try the below.

file
options
trust center
trust center settings
macro settings
 

Excelquestion35

New Member
Joined
Nov 29, 2021
Messages
35
Office Version
  1. 2016
Platform
  1. Windows
Thank you for the replies, I tried out both but it doesn't seem to work.

I made a very simplistic version of what I want.

Column B includes two drop down lists as shown below:

1638210165176.png


This is the code I would like to work with:
1638210229852.png
 

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
14,991
Office Version
  1. 365
Platform
  1. Windows
Have you tried completely closing down excel and restarting it?

It is possible that you had disabled events or rejected the macro warning, closing everything down and starting again should reset things. You need to make sure that you close everything, not just the workbook that is causing the problem.
 

Excelquestion35

New Member
Joined
Nov 29, 2021
Messages
35
Office Version
  1. 2016
Platform
  1. Windows
Thank you! That worked out fine in the simplistic version.

Strangely, the same code doesn't work on the document I want to apply it to.
It is a form with already some macros in it. I added this code to it, but for some reason it does not work on this document.
Any idea what could be wrong with this document?
 

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
14,991
Office Version
  1. 365
Platform
  1. Windows
If you're trying to use worksheet change in conjunction with the form then it is likely that events are being temporarily disabled while the form code executes.

If that is the case then you would need to re-enable events at the correct point for the code to trigger when it is needed, or if the change code is only being used for this one thing then it might be better to incorporate it directly into the button code rather than have multiple procedures tangled together like spaghetti. We would need to see the full code to advise further.
 

Excelquestion35

New Member
Joined
Nov 29, 2021
Messages
35
Office Version
  1. 2016
Platform
  1. Windows
How do I share my file with you? I don't see an option to attach a complete Excel file.
 

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
14,991
Office Version
  1. 365
Platform
  1. Windows
You can't attach a file directly to the forum, we only need the code which you can copy and paste here.

Please click on the </> icon above the reply box and paste your code into the popup window, not directly into the message box. This will ensure that your code is tagged correctly and that the formatting is preserved, otherwise it becomes messy and difficult to read.
 

Excelquestion35

New Member
Joined
Nov 29, 2021
Messages
35
Office Version
  1. 2016
Platform
  1. Windows
Looks like I found out the reason why my code dit not work. If I was clicking first on a Macro button that was already inside the document, then the code works afterwards. Now I only have to find out how I can change the sequence.
 

Forum statistics

Threads
1,175,794
Messages
5,899,527
Members
434,779
Latest member
Mr1510

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