Mel Smith
Well-known Member
- Joined
- Dec 13, 2005
- Messages
- 1,023
- Office Version
- 365
- Platform
- Windows
I'm trying to use some code from an inherited workbook but I cannot get the ComboBox to populate with a DropDown list. Where is my code wrong, please?
Private Sub ComboBox1_Change()
Dim ans As String
ans = ComboBox1.Value
Dim dteRow As Variant
Dim i As Long
Dim nn As Long
Dim Del As Variant
Dim sn As Variant
'these are sheet numbers
sn = Array(1, 2, 3)
' these are the column numbers shown below in the array
Del = Array(3, 4, 16, 6, 7, 8, 9, 10, 11, 12, 13, 14, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25)
nn = 1
For b = 1 To 3
With Sheets(sn(b - 1))
dteRow = Application.Match(ans, .Columns(1), 0)
If IsNumeric(dteRow) Then
For i = 1 To 34
Me.Controls("TextBox" & nn).Value = .Cells(dteRow, Del(i - 1))
nn = nn + 1
Next
Else
MsgBox ans & vbNewLine & "Not Found"
End If
End With
i = 1
Next
End Sub
Private Sub Userform1_Initialize()
ComboBox1.List = Sheets(1).Range("B4:B63").Value
End Sub
Thanks for your help.
Mel
Private Sub ComboBox1_Change()
Dim ans As String
ans = ComboBox1.Value
Dim dteRow As Variant
Dim i As Long
Dim nn As Long
Dim Del As Variant
Dim sn As Variant
'these are sheet numbers
sn = Array(1, 2, 3)
' these are the column numbers shown below in the array
Del = Array(3, 4, 16, 6, 7, 8, 9, 10, 11, 12, 13, 14, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25)
nn = 1
For b = 1 To 3
With Sheets(sn(b - 1))
dteRow = Application.Match(ans, .Columns(1), 0)
If IsNumeric(dteRow) Then
For i = 1 To 34
Me.Controls("TextBox" & nn).Value = .Cells(dteRow, Del(i - 1))
nn = nn + 1
Next
Else
MsgBox ans & vbNewLine & "Not Found"
End If
End With
i = 1
Next
End Sub
Private Sub Userform1_Initialize()
ComboBox1.List = Sheets(1).Range("B4:B63").Value
End Sub
Thanks for your help.
Mel