Question : Excel VBA UserInterFaceOnly problems when adding listbox

Hi,

I have a worksheet that is password protected so I found that I could use the UserInterFaceOnly property to allow my VBA code to make changes to my sheet whilst keeping the sheet protected.

This works up till a point, I can make changes through my code but it bugs out at one point below. The line .Add xlValidateList ..... is where the bug appears. The error message is Method ‘Add’ of object ‘Validation’ failed. Now when I unprotect the sheet and take out the UserInterFaceOnly property the same code below works perfectly!

       
1:
2:
3:
4:
5:
6:
Set RngListBox = Range("C" & i)
        
        With RngListBox.Validation
            .Add xlValidateList, xlValidAlertInformation, xlBetween, ListWeight
            .InCellDropdown = True
        End With


Any help would be great, thanks

Mark

Answer : Excel VBA UserInterFaceOnly problems when adding listbox

My bad - it should actually be DrawingObjects:=False.

I have to confess though that in my tests, it seems to be extremely buggy as to whether it works or not (sometimes it does, sometimes not) so I'd recommend you unprotect, add the validation and reprotect instead, to be honest.

Random Solutions  
 
programming4us programming4us