Populating data to cell using textbox inside a userform issue

wbstadeli

Board Regular
Joined
Mar 11, 2016
Messages
153
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I am trying to do two things with a userform.
#1 : add a new row to bottom of existing table, the table is called "Table1". (my current code does this part just fine)
#2 , populate the first cell in that new row with a textbox.text that is in a userform called UserForm1, the text box is called textbox50.

With my code i am using below, i get the following error: Run-time error '424': Object required

Would anyone be able to help me out to get this to work? It has something to do with the "textbox50.text" because i can get this to populate other data, for example selection.value = "Test" would work just fine.

Here is code:
Code:
Sub addrow()


Dim ws As Worksheet
Set ws = ActiveSheet
Dim tbl As ListObject
Set tbl = ws.ListObjects("Table1")
Dim newrow As ListRow
Set newrow = tbl.ListRows.Add
With newrow
    .Range(, 1).Select
    Selection.Value = TextBox50.Text
    End With
    
TextBox50.Text = ""


End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
.Range(, 1) is undefined, so would be .Range(1, 1). Try .Cells(1, 1):

Code:
With newrow
    .Cells(1, 1).Value = TextBox50.Text
End With
 
Upvote 0
.Range(, 1) is undefined, so would be .Range(1, 1). Try .Cells(1, 1):

Code:
With newrow
    .Cells(1, 1).Value = TextBox50.Text
End With

Thank you for your reply Jon, i found out that i needed to put this macro in the "Private Sub CommandButton1_Click()" that is in my userform, not in my worksheet module. Thanks agian!
 
Upvote 0

Forum statistics

Threads
1,223,250
Messages
6,171,036
Members
452,374
Latest member
keccles

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