VBA to post to table

Palacemad

New Member
Joined
May 19, 2019
Messages
42
Hi.

Still pretty new to VBA - I am trying to copy some data from one worksheet (Non-Continuous cells) to a table on another worksheet in the same workbook. Following some coding I have used on similar tasks (albeit not entering to a table) I have come up with the following coding:

Sub Reg_Calc_ToTable()


Dim src As Worksheet
Dimtbl As ListObject
Dim newrow As ListRow

Application.ScreenUpdating = False

Set src = ("Calculator - Regular")
Set dst = ("Regular Bets")
Set tbl = Ws.ListObjects("Reg_BetsTable")
Set ewrow = tbl.ListRows.Add

With newrow

dst.Cells(rw, "C") = src.Range("D7")
dst.Cells(rw, "D") = scr.Range("D8")
dst.Cells(rw, "E") = src.Range("D9")
dst.Cells(rw, "F") = scr.Range("D10")

Application.ScreenUpdating = True

End With

MsgBox "Data Transferred"


End Sub



I have tried to think logically - naming the sources and destinations and then identifying where teh source data is coming from and to which cells specifically it is going to.

However, I am immediately getting an error code relating to dimtbl As ListObject being invalid as it is outside its Type Block. I have no idea as to whether the rest of the code will work.

Can anyone help? I hope there is enough info here to make sense of what I am trying to do.

Thank you
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
The first issue is that you need to change "Dimtbl" to "Dim tbl". I thought is might have been a typo in your code, but then you repeated it in your description. Since you stated you were new to VBA, you may want to take a look at this website. It is an excellent resource for working with tables. I believe you will be able to figure this out with this resource.

https://www.thespreadsheetguru.com/blog/2014/6/20/the-vba-guide-to-listobject-excel-tables
 
Upvote 0

Forum statistics

Threads
1,214,415
Messages
6,119,382
Members
448,889
Latest member
TS_711

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