User-form and form button question

Daroh

Board Regular
Joined
Aug 19, 2016
Messages
62
Hi,

I have a form control button on Sheet 9 that opens up a userform. I want the data entered into the userform to be entered into a table (table3) on sheet 8 of a workbook. When the control button is on sheet 8 the code works perfect, but when the button is on page 9 it does not.

The code I am using is below:

Dim rng As Range
Set rng = ThisWorkbook.Worksheets("Sheet8").Range("Table3")
rng.Select

Set oNewRow = Selection.ListObject.ListRows.Add(AlwaysInsert:=True)
With ws
oNewRow.Range.Cells(1, 1).Value = Me.txtDate
oNewRow.Range.Cells(1, 2).Value = Me.txtName
oNewRow.Range.Cells(1, 3).Value = Me.txtGender
oNewRow.Range.Cells(1, 4).Value = Me.txtDOB

Any help would be appreciated.

Thanks.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Dim rng As Range
Set rng = ThisWorkbook.Worksheets("Sheet8").Range("Table3")
ThisWorkbook.Worksheets("Sheet8").select

rng.Select

Set oNewRow = Selection.ListObject.ListRows.Add(AlwaysInsert:=True)
With ws
oNewRow.Range.Cells(1, 1).Value = Me.txtDate
oNewRow.Range.Cells(1, 2).Value = Me.txtName
oNewRow.Range.Cells(1, 3).Value = Me.txtGender
oNewRow.Range.Cells(1, 4).Value = Me.txtDOB


''''''try with code
 
Last edited:
Upvote 0
Thanks Mukeshy12390 worked perfect.

One other question, is it possible to add a separate button that adds data to the same row put in a different column in the table? I have a table that I want to add data to but at different stages/steps using form controls i.e. Step 1/Button 1 - data/name/gender/DOB Step 2/Button 2 - weight and height Step 3 - Hip and waist Step 4 - Skinfold. The data needs to be entered on the same row from each step in a table. Thanks
 
Upvote 0

Forum statistics

Threads
1,224,830
Messages
6,181,228
Members
453,025
Latest member
Hannah_Pham93

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