# Method or Data Member Not Found



## johnohio (Dec 15, 2022)

Help!  I cannot get this to run.  I am creating a userform.  It even copied it from other spreadsheets where it worked fine, but it is not working.

*Error Message:*
_Compile Error
Method or Data Member Not Found_

*CODE:*

```
Private Sub UserForm_Initialize()
Application.ScreenUpdating = False

Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("cdb")

lastrow = ws.Range("a" & Rows.Count).End(xlUp).Row

For i = 2 To lastrow
    Me.TextBox1.AddItem ws.Cells(i, 1)
Next i

Application.ScreenUpdating = True
End Sub
```
`

Thanks Everyone!


----------



## Micron (Dec 15, 2022)

We're supposed to guess which of multiple code lines raises an error? 
Maybe it's Me.TextBox1.AddItem ws.Cells(i, 1) ? Perhaps that's because AddItem applies to a listbox or combobox, not a textbox.


----------



## DanteAmor (Dec 15, 2022)

johnohio said:


> Me.TextBox1.AddItem ws.Cells(i, 1)


The AddItem method is not used in a textbox.
That method is used in a combobox. If you already created the combobox, then it should look like this:


```
Private Sub UserForm_Initialize()
  Dim ws As Worksheet
  Dim lastrow As Long, i As Long
  
  Application.ScreenUpdating = False
  Set ws = ThisWorkbook.Sheets("cdb")
  
  lastrow = ws.Range("a" & Rows.Count).End(xlUp).Row
  For i = 2 To lastrow
      Me.ComboBox1.AddItem ws.Cells(i, 1)
  Next i
  
  Application.ScreenUpdating = True
End Sub
```


----------



## johnohio (Dec 15, 2022)

Thanks DaneeAmor, that fixed it
​


----------

