Add Data to table

Palacemad

New Member
Joined
May 19, 2019
Messages
42
Hi.

I am trying to add data from one worksheet to a table in another worksheet. I have so far come up with the following code, but this is causing the data to sit underneath the table, rather than be added to the next empty row. Can someone please help to guide me as to how I identify the table itself? I have tried replacing the dst as ListObject and then identify the ListObject but that keeps returning a fault each time. The name of the table is "Reg_BetTable" in the Worksheet "Regular Bets"


Thank you in advance for any guidance.

Sub Add_Data_RegBets()


Dim src As Worksheet
Dim dst As Worksheet
Dim rw As Long

Application.ScreenUpdating = False

' Set source and destination sheets
Set src = Sheets("Calculator - Regular")
Set dst = Sheets("Regular Bets")

' Find next available row on destination sheet
rw = dst.Cells(Rows.Count, "C").End(xlUp).Row + 1

' Populate values on destination sheet
dst.Cells(rw, "C") = src.Range("D7")
dst.Cells(rw, "D") = src.Range("D8")
dst.Cells(rw, "E") = src.Range("D11")
dst.Cells(rw, "F") = src.Range("D10")
dst.Cells(rw, "G") = src.Range("G7")
dst.Cells(rw, "H") = src.Range("D12")
dst.Cells(rw, "I") = src.Range("D9")
dst.Cells(rw, "J") = src.Range("G8")
dst.Cells(rw, "K") = src.Range("G9")
dst.Cells(rw, "L") = src.Range("G12")

Application.ScreenUpdating = True




End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Try this

Code:
Sub Add_Data_RegBets()
Dim src As Worksheet
Dim dst As Worksheet
Dim rw As Long
    
    Application.ScreenUpdating = False
    
    ' Set source and destination sheets
    Set src = Worksheets("Calculator - Regular")
    Set dst = Worksheets("Regular Bets")
    
    With dst.ListObjects("Reg_BetTable")
    
        .ListRows.Add
        ' Find next available row in destination table
        rw = .DataBodyRange.Rows.Count
    
         ' Populate values on destination sheet
        .DataBodyRange.Cells(rw, 1) = src.Range("D7")
        .DataBodyRange.Cells(rw, 2) = src.Range("D8")
        .DataBodyRange.Cells(rw, 3) = src.Range("D11")
        .DataBodyRange.Cells(rw, 4) = src.Range("D10")
        .DataBodyRange.Cells(rw, 5) = src.Range("G7")
        .DataBodyRange.Cells(rw, 6) = src.Range("D12")
        .DataBodyRange.Cells(rw, 7) = src.Range("D9")
        .DataBodyRange.Cells(rw, 8) = src.Range("G8")
        .DataBodyRange.Cells(rw, 9) = src.Range("G9")
        .DataBodyRange.Cells(rw, 10) = src.Range("G12")
    End With
    
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thank you very much! That generally works, looks like it was just the one line of code that was missing.

The only issue, and it is very minor and not a major problem is that it is not filling out the first row of the table, it is immediately going to the row below. It then seems to work properly. I'm not really that bothered, more intrigued as to why it is doing that.
 
Upvote 0

Forum statistics

Threads
1,223,905
Messages
6,175,297
Members
452,633
Latest member
DougMo

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