Extra lines in Combobox

Skyybot

Well-known Member
Joined
Feb 18, 2023
Messages
875
Office Version
  1. 365
Platform
  1. Windows
Can anyone tell me why there are two extra, blank lines at the end of my Combobox? (Sorry for the pic. I got an Overflow error with XL2BB)
1695423499339.png

VBA Code:
Private Sub ComboBox1_DropButtonClick()
Dim cfName As String, clName As String, custList As Range
Dim lRow As Long, cell As Range, custData As Range
Dim i As Long

Me.Cells(1, 1).Select
lRow = Me.Rows(Me.Rows.Count).End(xlUp).Row
Set custList = Me.Range("A2:G" & lRow)

With Me.ComboBox1
    .ColumnCount = 2
    .ColumnHeads = False
    .ListFillRange = custList.Range(custList.Cells(1, 1), custList.Cells(lRow, 2)).Address
    .DropDown
End With

End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
default listrows on the combobox is 8
try
VBA Code:
With Me.ComboBox1
    .ListRows = 5
    .ColumnCount = 2
    .ColumnHeads = False
    .ListFillRange = custList.Range(custList.Cells(1, 1), custList.Cells(lRow, 2)).Address
    .DropDown
End With
 
Upvote 0
Can anyone tell me why there are two extra, blank lines at the end of my Combobox? (Sorry for the pic. I got an Overflow error with XL2BB)
View attachment 99174
VBA Code:
Private Sub ComboBox1_DropButtonClick()
Dim cfName As String, clName As String, custList As Range
Dim lRow As Long, cell As Range, custData As Range
Dim i As Long

Me.Cells(1, 1).Select
lRow = Me.Rows(Me.Rows.Count).End(xlUp).Row
Set custList = Me.Range("A2:G" & lRow)

With Me.ComboBox1
    .ColumnCount = 2
    .ColumnHeads = False
    .ListFillRange = custList.Range(custList.Cells(1, 1), custList.Cells(lRow, 2)).Address
    .DropDown
End With

End Sub

Upon testing, this line is picking a range that ends two rows below the last used cell.

VBA Code:
.ListFillRange = custList.Range(custList.Cells(1, 1), custList.Cells(lRow, 2)).Address
 
Upvote 0
Upon testing, this line is picking a range that ends two rows below the last used cell.

VBA Code:
.ListFillRange = custList.Range(custList.Cells(1, 1), custList.Cells(lRow, 2)).Address

This ended up working for me... I don't understand why the range was offset so much.
VBA Code:
.ListFillRange = custList.Range(custList.Cells(0, 1), custList.Cells(lRow - 2, 2)).Address

However, you are starting in row 3, so maybe this:
VBA Code:
.ListFillRange = custList.Range(custList.Cells(1, 1), custList.Cells(lRow - 2, 2)).Address
 
Upvote 0
Careful, there is a hidden Row. I couldn't get a list without First Name Last Name at the top (no Column Headers displayed Column1 , Column2). I was trying to get a list without headers, or any other values that aren't in the list.
 
Upvote 0
Careful, there is a hidden Row. I couldn't get a list without First Name Last Name at the top (no Column Headers displayed Column1 , Column2). I was trying to get a list without headers, or any other values that aren't in the list.

I think if you use the line I suggested with the first cell reference being Cells(0,1) you can use row 2 properly.
 
Upvote 0
This ended up working for me... I don't understand why the range was offset so much.
VBA Code:
.ListFillRange = custList.Range(custList.Cells(0, 1), custList.Cells(lRow - 2, 2)).Address

However, you are starting in row 3, so maybe this:
VBA Code:
.ListFillRange = custList.Range(custList.Cells(1, 1), custList.Cells(lRow - 2, 2)).Address
I just caught that. I don't know why the Range was Offset so much either. I took clues from @dreid1011 and @NoSparks and got it.
VBA Code:
Private Sub ComboBox1_DropButtonClick()
Dim cfName As String, clName As String, custList As Range
Dim lRow As Long, cell As Range, custData As Range
Dim i As Long

Me.Cells(1, 1).Select
lRow = Me.Rows(Me.Rows.Count).End(xlUp).Row
Set custList = Me.Range("A2:G" & lRow)

With Me.ComboBox1
    .ListRows = custList.Rows.Count
    .ColumnCount = 2
    .ColumnHeads = False
    .ListFillRange = custList.Range(custList.Cells(1, 1), custList.Cells(lRow - 2, 2)).Address
    .DropDown
End With

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,212
Messages
6,123,654
Members
449,113
Latest member
Hochanz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top