How to dynamically add values starting at a specific cell until the last row and add the contents to a combobox

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
563
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
The code below works, however, I would like the code to find and add all the items dynamically.

Code:
Private Sub ComboBox1_Enter()   
    If cmbSDPFLine.Value = "Line 1" Then
        With Me.ComboBox1
            .Clear
            .List = WorksheetFunction.Transpose(Sheets("Sheet1").Range("A3:A10").Value)
        End With
    End If
End Sub

I tried to make the code below dynamic but I get a "compile error: Method or data member not found".
Code:
Private Sub ComboBox1_Enter()
    If cmbSDPFLine.Value = "Line 1" Then
        With Me.ComboBox1
            .Clear
            .List = .Range("A3", .Range("A" & Rows.Count).End(xlUp).Offset)
        End With
    End If


End Sub
When I select debug the highlighted code is:
Code:
.Range
Followed by:
Code:
("A" & Rows.Count).End(xlUp))

Thank You
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
To start with you haven't included a value in the Offset in the line below
Code:
.List = .Range("A3", .Range("A" & Rows.Count).End(xlUp).Offset)
what error occurs when you use
Code:
.List = .Range("A3", .Range("A" & Rows.Count).End(xlUp).Offset(1))
 
Upvote 0
You also haven't referenced the sheet so test

Code:
.List = Sheets("Sheet1").Range("A3", Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1))
 
Upvote 0
Thank you for your help. When I put replace your code with mine. I get a "Run time error '381': Could not set the list property. Invalid property array index.":confused:
Code:
Private Sub ComboBox1_Enter()
If cmbSDPFLine.Value = "SDPF - Line 1" Then
        With Me.ComboBox1
            .Clear
            .List = Sheets("Sheet1").Range("A3", Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1))
        End With
End Sub
When I click debug, the below code is highlighted in yellow.
Code:
[COLOR=#333333].List = Sheets("Sheet1").Range("A3", Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1))[/COLOR]
 
Last edited:
Upvote 0
Try
Code:
            .List = Sheets("Sheet1").Range("A3", Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp)).Value
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,603
Members
449,038
Latest member
Arbind kumar

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