View Full Version : [SOLVED:] Combo Box Index select
av8tordude
11-07-2019, 11:26 PM
I have a userform that loads symbols in a combo box from column A that do not have a date listed in column D. When I select the symbol from the combo box, I would like to select the row corresponding to my selection. Can someone assist with a code that can achieve this.
Thank you kindly
Private Sub cbName_Change()
If cbName.ListIndex > -1 Then
With Sheets("sheet1").Range("a5").CurrentRegion
.AutoFilter
.AutoFilter 1, cbName.Value
.AutoFilter 4, "="
End With
End If
End Sub
av8tordude
11-08-2019, 02:52 AM
Hi Mana....The code is filtering. Can you code it to only select the row?
Thank you for you kind help
Option Explicit
Private Sub UserForm_Initialize()
Dim r As Range, c As Range
Dim a()
Dim n As Long
On Error Resume Next
Set r = Sheets("sheet1").Range("a6").CurrentRegion.Columns(4).SpecialCells(xlCellTypeBlanks)
On Error GoTo 0
If r Is Nothing Then Exit Sub
ReDim a(r.Count - 1, 1)
For Each c In r
a(n, 0) = c.Offset(, -3).Value
a(n, 1) = c.Address(, , , True)
n = n + 1
Next
With cbName
.ColumnCount = 2
.BoundColumn = 1
.TextAlign = fmTextAlignLeft
.ColumnWidths = "30;0"
.List() = a()
End With
End Sub
'
Private Sub cbName_Change()
If cbName.ListIndex > -1 Then
Application.Goto Range(cbName.List(cbName.ListIndex, 1))
End If
End Sub
av8tordude
11-08-2019, 04:14 AM
Thank you Mana...Is there a way for it to select the cell in column A once it finds the selection?
ReDim a(r.Count - 1, 1)
For Each c In r.Offset(, -3)
a(n, 0) = c.Value
a(n, 1) = c.Address(, , , True)
n = n + 1
Next
av8tordude
11-08-2019, 04:34 AM
I have data in rows 1 - 4 and a header in Row 5, How can I account for this. Because I have 4 spaces in the combo box preceding the list
On Error Resume Next
Set r = Sheets("sheet1").Range("a6")
Set r = Range(r, r.End(xlDown))
Set r = r.Columns(4).SpecialCells(xlCellTypeBlanks)
On Error GoTo 0
av8tordude
11-08-2019, 04:50 AM
Perfect...Thank you very much for you patience, understanding, and expertise.
Cheers
What did you learn from this thread ?
av8tordude
11-08-2019, 05:36 AM
Digesting the variables. I'm using F8 to step through the code to understand what's happening.
I didn't see any VBA code from your side.
As Mana showed you: the userform is 100% redundant.
Private Sub Workbook_Open()
Sheet1.Cells(6, 1).CurrentRegion.AutoFilter 4, "="
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.