Filling formulas over to the right into a new column added

gaudrco

Board Regular
Joined
Aug 16, 2019
Messages
203
I have a code for a button that creates a new column at theend of a table. After the new column is added, I would like to have theformulas from the previous table column to fill into the new column. The datain the table should be the only formulas filling to the right (table headersshould not fill, just the data from the table). Here is the code for adding the newcolumn:

Code:
With Sheets("Competitor Comparison").ListObjects("CompComparisonTable")
    .ListColumns.Add(.ListColumns.Count + 1).Name = Range("C2")
    .ListColumns(.ListColumns.Count - 1).Range.EntireColumn.Copy
    .ListColumns(.ListColumns.Count).Range.EntireColumn.PasteSpecial Paste:=xlPasteFormats
End With


Please and thank you
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
how about
Code:
    Dim ws As Worksheet, oLo As ListObject

Set ws = Sheets("Competitor Comparison")
With ws
    Set oLo = .ListObjects("CompComparisonTable")
    With oLo
        .ListColumns.Add
        oLo.HeaderRowRange.Cells(1, .ListColumns.Count).Value = Range("C2")
        ws.Range(.ListColumns(.ListColumns.Count - 1).DataBodyRange, .ListColumns(.ListColumns.Count).DataBodyRange).FillRight
    End With
End With
 
Upvote 0
Upvote 0
I tried it and still no luck. Everything worked up until the last line with the autofillright. I got a runtime error 424: Object required

And to Joe4: I apologize I didn’t know that rule but that is the only other place my question is posted
 
Upvote 0
And to Joe4: I apologize I didn’t know that rule but that is the only other place my question is posted
OK. Just keep that in mind, and be sure to do that if you want to Cross-Post again in the future.
 
Upvote 0
I have still been at this and I had an idea. I used the Macro Recorder feature in Excel to create a base understanding of what the code should look like. Here is the recording:
Code:
Private Sub CommandButton1_Click()    
Sheets("Competitor Comparison").Select
    Range("CompComparisonTable[Competitor_5]").Select
    Selection.AutoFill Destination:=Range( _
        "CompComparisonTable[[Competitor_5]:[Competitor_6]]"), Type:=xlFillDefault
    Range("CompComparisonTable[[Competitor_5]:[Competitor_6]]").Select
    End Sub

I know this is probably incomplete because it was recorded but it definitely helped me. So the thing that needs to change in the code is:

Instead of [Competitor_5], that should be the second to last DataBodyRange column.
Instead of [Competitor_6), that should be the last DataBodyRange column.

Did this make it easier to understand?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,217
Members
453,024
Latest member
Wingit77

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