Forum Discussion
Allan_Smillie
Apr 23, 2024Copper Contributor
copy selected fields and insert into table
Good morning, I am looking for advice on how to start with a problem I have. I have a sheet where users input information. The data is stored in 6 rows, E7:I12 with each row being a new record. ...
- Apr 23, 2024
For example:
Sub CopyData() Dim ws As Worksheet Dim wt As Worksheet Dim tb As ListObject Dim lr As ListRow Dim s As Long Application.ScreenUpdating = False Set ws = Worksheets("Calc") Set wt = Worksheets("MyTotal") Set tb = wt.ListObjects("TblTest") For s = 7 To 12 If ws.Range("E" & s) <> "" Then Set lr = tb.ListRows.Add lr.Range.Resize(1, 6).Value = ws.Range("E" & s).Resize(1, 6).Value lr.Range(1, 7).Value = ws.Range("F16").Value End If Next s Application.ScreenUpdating = True End Sub
HansVogelaar
Apr 23, 2024MVP
For example:
Sub CopyData()
Dim ws As Worksheet
Dim wt As Worksheet
Dim tb As ListObject
Dim lr As ListRow
Dim s As Long
Application.ScreenUpdating = False
Set ws = Worksheets("Calc")
Set wt = Worksheets("MyTotal")
Set tb = wt.ListObjects("TblTest")
For s = 7 To 12
If ws.Range("E" & s) <> "" Then
Set lr = tb.ListRows.Add
lr.Range.Resize(1, 6).Value = ws.Range("E" & s).Resize(1, 6).Value
lr.Range(1, 7).Value = ws.Range("F16").Value
End If
Next s
Application.ScreenUpdating = True
End Sub- Allan_SmillieApr 23, 2024Copper Contributorhans, thank you for this. It is easy to follow and does what I need, thank you.