Been trying to figure this out on my own for two days and I just suck!! Should be simple for someone. Got some Contextures code and have modified it some. Here's the jist.....
1) The top of the VBA code works like a charm, calling a set of Combo boxes (tempCombo & tempCombo2) into column B and column C cells that contain "data validation". I am using combo boxes because the dang font size is way too small to be seen in an excel data validation drop down list at lower window magnification (excel should give options for this on going issue....arrg anyway!!!!)
2) B7:C18 all have data validation.
3) Cells B7:B18 call on are Name Defined as "Animal".
4) Cells C7:C18 have a "dependent" formula in the data validation formula bar like this: =INDIRECT($B7&"x"). This formula takes the chosen value from the B cell (dog, cat, birds, elephant) and adds an "x" to the word e.g. dogx
5) dogx, birdsx etc. are defined names for the various type of birds, dogs etc. If I choose dog in B7 then C7 should populate with a list "boxer, lab, retriever, poodle, pug. But ALAS nothing but A$$, my code has failed me (observe):
Thanks for any help provided in adavance.
[/SIZE]
1) The top of the VBA code works like a charm, calling a set of Combo boxes (tempCombo & tempCombo2) into column B and column C cells that contain "data validation". I am using combo boxes because the dang font size is way too small to be seen in an excel data validation drop down list at lower window magnification (excel should give options for this on going issue....arrg anyway!!!!)
2) B7:C18 all have data validation.
3) Cells B7:B18 call on are Name Defined as "Animal".
4) Cells C7:C18 have a "dependent" formula in the data validation formula bar like this: =INDIRECT($B7&"x"). This formula takes the chosen value from the B cell (dog, cat, birds, elephant) and adds an "x" to the word e.g. dogx
5) dogx, birdsx etc. are defined names for the various type of birds, dogs etc. If I choose dog in B7 then C7 should populate with a list "boxer, lab, retriever, poodle, pug. But ALAS nothing but A$$, my code has failed me (observe):
Thanks for any help provided in adavance.
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Set ws = ActiveSheet
On Error Resume Next
If tempCombo.Visible = True Then
With tempCombo
.Top = 10
.Left = 10
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
.Value = ""
End With
End If
If tempCombo2.Visible = True Then
With tempCombo2
.Top = 10
.Left = 10
.Visible = False
.LinkedCell = ""
.Value = ""
End With
End If
On Error GoTo errHandler
If Target.Count > 1 Then GoTo exitHandler
'the following segment of code insures that the correct combo box is used in the correct column (left column vs. right column)
On Error GoTo errHandler
If (Target.Column = 3 Or Target.Column = 2) And (Target.Validation.Type = 3) Then
If Target.Column = 2 Then
Set cboTemp = ws.OLEObjects("TempCombo2")
ElseIf Target.Column = 3 Then
Set cboTemp = ws.OLEObjects("TempCombo")
Else
Exit Sub
End If
With cboTemp
'the following code inserts the combo boxes into the cells containing cell validation only
.LinkedCell = Target.Address
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 3
.Height = Target.Height + 5
If Target.Column = 3 Then
.ListFillRange = Cells(Target.Row, Target.Column - 1)
End If
.ListFillRange = ws.Range(str).Address
If .ListFillRange <> str Then
'for dynamic named ranges
str = Target.Validation.Formula1
str = Right(str, Len(str) - 1)
Set wb = ActiveWorkbook
Set nm = wb.Names(str)
Set wsNm = wb.Worksheets _
(nm.RefersToRange.Parent.Name)
Set Rng = wsNm.Range _
(nm.RefersToRange.Address)
.ListFillRange = "=INDIRECT($B8 & ""x"")"
End If
End With
cboTemp.Activate
End If
On Error GoTo errHandler
If Target.Count > 1 Then GoTo exitHandler
exitHandler:
Application.ScreenUpdating = True
Application.EnableEvents = True
Exit Sub
errHandler:
Resume exitHandler
End Sub
Last edited by a moderator: