Selecting Last Column Header of a Table to paste into

TomasTeix

New Member
Joined
May 8, 2024
Messages
10
Office Version
  1. 365
Platform
  1. Windows
Hi! i´ve been struggling with this one for a bit now. I want to paste something into the Last Column Header of a Table. I´ve tried with following code:

VBA Code:
ActiveSheet.ListObjects("TableName").HeaderRowRange(LastColumn).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

I´´ve verified if I was in the active sheet, and if the table name was correct already. By testing this code, it pastes on the cell before the First Column header, and not on the last column header.
Any help?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
If you want to change the value of the last column in the header then perhaps the below will help:
VBA Code:
Sub test()
    Dim ws As Worksheet
    
    Set ws = ActiveSheet
    ws.Range("A1").Copy
    
    ws.ListObjects("TableName").HeaderRowRange.End(xlToRight).PasteSpecial xlPasteValues
End Sub
 
Upvote 1
If you want to change the value of the last column in the header then perhaps the below will help:
VBA Code:
Sub test()
    Dim ws As Worksheet
   
    Set ws = ActiveSheet
    ws.Range("A1").Copy
   
    ws.ListObjects("TableName").HeaderRowRange.End(xlToRight).PasteSpecial xlPasteValues
End Sub
THANKS
 
Upvote 0
If you want to change the value of the last column in the header then perhaps the below will help:
VBA Code:
Sub test()
    Dim ws As Worksheet
   
    Set ws = ActiveSheet
    ws.Range("A1").Copy
   
    ws.ListObjects("TableName").HeaderRowRange.End(xlToRight).PasteSpecial xlPasteValues
End Sub
okay now I have a new challange. How do I make this so that the tables becomes dynamically growing?
VBA Code:
ActiveSheet.ListObjects("TableName").Cells(1, Columns.Count).End(xlToRight).PasteSpecial xlPasteValues
Why doesn´t this work?
 
Upvote 0
If you want to paste into the cell to the right of the last header cell to make a new column then you can try the below:
VBA Code:
Sub test()
    Dim ws As Worksheet
   
    Set ws = ActiveSheet
    ws.Range("A1").Copy
   
    ws.ListObjects("TableName").HeaderRowRange.End(xlToRight).Offset(, 1).PasteSpecial xlPasteValues
End Sub
 
Upvote 1
Solution
If you want to paste into the cell to the right of the last header cell to make a new column then you can try the below:
VBA Code:
Sub test()
    Dim ws As Worksheet
  
    Set ws = ActiveSheet
    ws.Range("A1").Copy
  
    ws.ListObjects("TableName").HeaderRowRange.End(xlToRight).Offset(, 1).PasteSpecial xlPasteValues
End Sub
UR A LEGEND
 
Upvote 0

Forum statistics

Threads
1,223,869
Messages
6,175,088
Members
452,611
Latest member
bls2024

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