Add Data to table
Results 1 to 3 of 3

Thread: Add Data to table
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    May 2019
    Posts
    23
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Add Data to table

    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

  2. #2
    Rules violation
    Join Date
    Jan 2012
    Posts
    912
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Add Data to table

    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

  3. #3
    New Member
    Join Date
    May 2019
    Posts
    23
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Add Data to table

    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.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •