How to do a dynamic table with constant row values in VBA

TomasTeix

New Member
Joined
May 8, 2024
Messages
10
Office Version
  1. 365
Platform
  1. Windows
I´m new using VBA. I´ve tried a few methods to make a dynamic table where when new collumns are added, the values of the rows, continue throughout. But I haven´t found a solution. Any Help?
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
can you explain a bit more about what you're trying to do?
 
Upvote 0
We might need an example here. I'm not sure I understand what you mean by "the values of the rows continue throughout".
 
Upvote 0
Header 1Header 2Header 3Header 4Header 5Header 6
888888
333333

Something like this, where by adding a new column header, and a new columns, the 8s and the 3s continue.
 
Upvote 0
Header 1Header 2Header 3Header 4Header 5Header 6
888888
333333

Something like this, where by adding a new column header, and a new columns, the 8s and the 3s continue.
I´m trying to this now by simply copying the first 8 and 3, to the upcoming Column like this:
VBA Code:
Dim LastColumn As Long
LastColumn = Cells(1, Columns.Count).End(xlToLeft).Column


ActiveSheet.Range("A1:A2").Copy
ActiveSheet.ListObjects("TableName").LastColumn.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
the error 438 comes on the line "ActiveSheet.ListObjects("TableName").LastColumn.Select"

any help?
 
Upvote 0
You can try :
VBA Code:
Sub AddData2Col()

Dim ws As Worksheet
Dim LastColumn As Long

Set ws = ThisWorkbook.Sheets("Sheet1")

LastColumn = Cells(2, Columns.Count).End(xlToLeft).Column + 1

ActiveSheet.Range("A2:A3").Copy

Dim rng As Range

Set rng = ws.Range(ws.Cells(2, LastColumn), ws.Cells(ws.Rows.Count, LastColumn))

rng.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

End Sub
 
Upvote 0
This doesn´t work because I have more than one table in this Sheet. Like this the numbers are implemented into the first cells of the first table
 
Upvote 0

Forum statistics

Threads
1,221,499
Messages
6,160,169
Members
451,629
Latest member
MNexcelguy19

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