I have some code that takes a validation list and enters it into a combo box which allows the user to use a form of autocomplete and then outputs the results into the desired cell, it used to work, but for a reason i cannot find the code has stopped working.. when i try copy pasting into a new workbook, it fails again!
what have i messed up?
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim str As String Dim cboTemp As OLEObject Dim ws As Worksheet 'Dim wsList As Worksheet Set ws = ActiveSheet On Error GoTo errhandler 'Set wsList = Sheets("ValidationLists") If Target.count > 1 Then GoTo exitHandler Set cboTemp = ws.OLEObjects("TempCombo") On Error Resume Next If cboTemp.Visible = True Then With cboTemp .Top = 10 .Left = 10 .ListFillRange = "" .LinkedCell = "" .Visible = False .Value = "" End With End If On Error GoTo errhandler If Target.Validation.Type = 3 Then 'if the cell contains a data validation list Application.EnableEvents = False 'get the data validation formula str = Target.Validation.Formula1 str = Right(str, Len(str) - 1) With cboTemp 'show the combobox with the list .Visible = True .Left = Target.Left .Top = Target.Top .Width = Target.Width + 15 .Height = Target.Height + 5 .ListFillRange = str .LinkedCell = Target.Address End With cboTemp.Activate End If exitHandler: Application.ScreenUpdating = True Application.EnableEvents = True Exit Sub errhandler: Resume exitHandler End Sub
Last edited by Jollyfrog; 09-28-2010 at 06:51 AM.
maybe:
If validationrules in the worksheet have been removed the code won't work. Start checking the worksheet.Private Sub Worksheet_SelectionChange(ByVal Target As Range) on error goto XL90 If Target.count > 1 Then Exit Sub application.screenupdating =False With OLEObjects("TempCombo") .Visible=false If Target.Validation.Type = 3 Then .Left = Target.Left .Top = Target.Top .Width = Target.Width + 15 .Height = Target.Height + 5 .ListFillRange = mid(Target.Validation.Formula1,2) .LinkedCell = Target.Address .Visible=True End With End If XL90: Application.ScreenUpdating = True End Sub
Last edited by snb; 09-28-2010 at 05:59 AM.
Stopped working? What doesn't it do that it used to do? How long is it since it last worked? What's changed in the meantime? More data? Less data? New structure ... more or less columns? Additional worksheets? Updates to Windows, Office, Excel ... ?
One way to test it is to comment out the error handling and see where it breaks. You could also put a break point on the code (Set ws = ActiveSheet) and step through (using F8) from there.
For someone in the forum to provide assistance, it would be helpful if you uploaded a sample workbook with some typical, desensitized data.
Regards
hmm tried the suggested code... validation rules were active.. but no luck.. thanks for your sugestion!
You're welcome. Thanks for the feedback.
You can type Application.EnableEvents in the Immediate window ... saves creating a macro to do it.
I'm still unsure what's changed ... if the code used to work, why doesn't it now? What's different in the version that does work?
All academical perhaps ...
Regards
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks