2

The below code works as long as there are more than one instance of the search criteria. However, if there is only one row that is listed as the what in the find function I receive the error "Could not set the list property. Invalid property array index"

Private Sub UserForm_Initialize()

Dim iRow As Integer, iMax As Integer

iRow = Cells.Find(What:="New Jersey Audit Adjustment", _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Row

iMax = Cells.Find(What:="New Jersey Audit Adjustment", _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, _
    MatchCase:=False, SearchFormat:=False).Row
 
Me.ComboBox1.List = Worksheets("C-Proposal-19").Range("B" & iRow & ":B" & iMax).Value
Me.ComboBox2.List = Worksheets("C-Proposal-19").Range("B" & iRow & ":B" & iMax).Value
Me.ComboBox3.List = Worksheets("C-Proposal-19").Range("B" & iRow & ":B" & iMax).Value
Me.ComboBox4.List = Worksheets("C-Proposal-19").Range("B" & iRow & ":B" & iMax).Value
Me.ComboBox5.List = Worksheets("C-Proposal-19").Range("B" & iRow & ":B" & iMax).Value
    
End Sub

The error occurs here Me.ComboBox1.List = Worksheets("C-Proposal-19").Range("B" & iRow & ":B" & iMax).Value if I have one row listed with "New Jersey Audit Adjustment"

1
  • From the Documentation: "Use List to copy an entire two-dimensional array of values to a control. Use AddItem to load a one-dimensional array or to load an individual element." The error is due to Range.Value returning a single value, which is then rejected by List as an invalid input. Commented Jan 14, 2022 at 20:00

1 Answer 1

1

When your range contains one cell, the .value will give you a value instead of an array. As the .list expects an array you could fill an array with one element or use addItem (see below)

If Worksheets("C-Proposal-19").Range("B" & iRow & ":B" & iMax).Cells.Count = 1 Then
    Me.ComboBox1.AddItem Worksheets("C-Proposal-19").Range("B" & iRow & ":B" & iMax).Value
    
Else
    Me.ComboBox1.List = Worksheets("C-Proposal-19").Range("B" & iRow & ":B" & iMax).Value
    
End If
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.