Find table on copied worksheet

Robby19

Board Regular
Joined
Mar 19, 2018
Messages
227
I have a userform that copies a worksheet that contains a table. I need the next userform to transfer inputted data. The problem I am having is that when the new worksheet is copied, the name of the table changes.

How can I change the below to find the only table on the worksheet and input the data?

Code:
With ActiveWorkbook.ActiveSheet.ListObjects("Table3")
    lrow = .ListColumns(1).Range.Rows.Count
        .DataBodyRange.Cells(lrow, 1).Value = "Active"
        .DataBodyRange.Cells(lrow, 2).Value = Me.GName.Value
End With
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Change ListObjects("Table3") to ListObjects(1).
 
Upvote 0
Works like a charm. What do I need to add in order to transfer the value of a textbox to a specific cell, for example B1, on the sheet and NOT in the table?
 
Upvote 0
It would be something like this:
Sheets("David").Range("B1").value=Textbox1.value
 
Upvote 0
One more question regarding this if you don't mind. I found the below code and tried to adjust it to what I need. I am trying to make it so it looks at the only table on the sheet, and the 7th column of that table. I then need it to loop through and add +5 to each cell in the 7th column.

Whenever I try to run it now I get a Sub or Function not defined error and ListObjects(1) is highlighted.

Code:
Dim RNG As Range
        Dim aCell As Range
        'set the range to be the second column of the table
        Set RNG = ListObjects(1).ListColumns(7).SpecialCells(xlCellTypeVisible)
            For Each aCell In RNG.Cells
              MsgBox aCell.Value
        Next aCell
 
Upvote 0
Try this:
Code:
Sub My_Table()
'Modified  10/4/2018  1:49:34 AM  EDT
Application.ScreenUpdating = False
Dim r As Range
Dim ans As Long
With ActiveSheet.ListObjects(1).DataBodyRange
ans = .Columns(7).Rows.Count
    For Each r In .Cells(1, 7).Resize(ans)
        r.Value = r.Value + 5
    Next
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,331
Members
449,077
Latest member
jmsotelo

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