Populating a table in different sheet

karolina1406

Board Regular
Joined
Apr 18, 2016
Messages
110
Office Version
  1. 365
Platform
  1. Windows
hi All,
I have a UserForm in each tab on my spreadsheet. It's the same for each sheet. I use below code to send the info from the Userform to the master table in a different sheet. A Table that i want to populate is called ReserveSpaceRequests and ints in a ReserveSpaceReq sheet. Belo code works is the UserForm is placed in the ReserveSpaceReq sheet but it doesn't work from any other sheet... I am getting an error message at rng.Select. Any ideas why?
VBA Code:
Dim oNewRow As ListRow
Dim rng As Range
Set rng = ThisWorkbook.Worksheets("ReserveSpaceReq").Range("ReserveSpaceRequests")
rng.Select
Set oNewRow = Selection.ListObject.ListRows.Add(AlwaysInsert:=True)

With ws
    oNewRow.Range.Cells(1, 3).Value = Me.TextBox1.Value
    oNewRow.Range.Cells(1, 4).Value = Me.TextBox2.Value
    oNewRow.Range.Cells(1, 5).Value = Me.ComboBox1.Value
    oNewRow.Range.Cells(1, 2).Value = Me.TextBox3.Value
    oNewRow.Range.Cells(1, 8).Value = Me.TextBox4.Value
    oNewRow.Range.Cells(1, 10).Value = Me.TextBox7.Value
    oNewRow.Range.Cells(1, 11).Value = Me.TextBox9.Value
    oNewRow.Range.Cells(1, 12).Value = Me.TextBox13.Value
    
End With
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
How about
VBA Code:
   Dim oNewRow As ListRow
   Dim rng As Range
   Set rng = ThisWorkbook.Worksheets("ReserveSpaceReq").Range("ReserveSpaceRequests")
   Set oNewRow = rng.ListObject.ListRows.Add(AlwaysInsert:=True)
   
   With oNewRow.Range
      .Cells(1, 3).Value = Me.TextBox1.Value
      .Cells(1, 4).Value = Me.TextBox2.Value
      .Cells(1, 5).Value = Me.ComboBox1.Value
      .Cells(1, 2).Value = Me.TextBox3.Value
      .Cells(1, 8).Value = Me.TextBox4.Value
      .Cells(1, 10).Value = Me.TextBox7.Value
      .Cells(1, 11).Value = Me.TextBox9.Value
      .Cells(1, 12).Value = Me.TextBox13.Value
   End With
 
Upvote 0

Forum statistics

Threads
1,215,151
Messages
6,123,316
Members
449,094
Latest member
Chestertim

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