Method or Data Member Not Found

johnohio

New Member
Joined
May 12, 2005
Messages
48
Office Version
  1. 2016
Platform
  1. Windows
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:
VBA 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!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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.
 
Upvote 0
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:

VBA Code:
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
 
Upvote 0
Solution

Forum statistics

Threads
1,215,133
Messages
6,123,233
Members
449,092
Latest member
SCleaveland

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