Extra lines in Combobox

Skyybot

Well-known Member
Joined
Feb 18, 2023
Messages
1,229
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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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,224,827
Messages
6,181,197
Members
453,022
Latest member
RobertV1609

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