VBA Adding Data validation dropdown does not work on second run

szita2000

Board Regular
Joined
Apr 25, 2012
Messages
101
Office Version
  1. 365
Platform
  1. Windows
Hi All.

This is a bit of mystery.
In a macro I place Data validation Dropdown in to a range.

I am using this bit of code for this:

VBA Code:
'Adding the Data validation listboxes to ***listrange***
                
                With listrange.Validation
                    .Delete
                    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=rngTipus"
                    .IgnoreBlank = True
                    .InCellDropdown = True
                    .InputTitle = ""
                    .ErrorTitle = ""
                    .InputMessage = ""
                    .ErrorMessage = ""
                    .ShowInput = True
                    .ShowError = True
                End With

When I run the macro for the first time. It places the dropdowns O.K.
If I clear everything and rerun the macro the second time I do not have dropdowns in the cells.

The things I checked:
  1. I put ActiveX buttons on the sheet at the same time (actually before this snippet goes) - They don't seem to be taking focus
  2. I checked if Application.EnableEvents is TRUE- It is
  3. I checked Application.ScreenUpdating is TRUE - It is
  4. I commented out all Screenupdating and manual calculation from the code

Wonder if I should get rid of the .delete in the listrange.Validation?...

Let me know if you want to see the rest of the code.

Thanks
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
No, you should keep the Delete.

Is there any error handling that would be hiding errors?
 
Upvote 0
No, you should keep the Delete.

Is there any error handling that would be hiding errors?
Hi Rory.
Thanks for the quick reply.

No. there is no error handling, or resume next

However, I added DoEvents at the end of the dropdown creation and It seems that it worked.

Thanks for the help though.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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