I have a command button that adds a column to a table. The table has formulas that need to be filled to the right with each new column added. Here is the vba that I have been using to achieve this:
The fill command is not behaving correctly. When I click the button to add a new column, the new column does not fill with the correct column starting point.
Here are the reference column formulas:
=IFERROR(INDEX('Competitor Comparison Data'!T:T,MATCH($B$3,'Competitor Comparison Data'!$D:$D,0)+ROWS($A$8:$A8)-1),"No Match")
=IFERROR(INDEX('Competitor Comparison Data'!U:U,MATCH($B$3,'Competitor Comparison Data'!$D:$D,0)+ROWS($A$8:$A8)-1),"No Match")
Here is the new column formula that is filled into the new column when the button is clicked:
=IFERROR(INDEX('Competitor Comparison Data'!W:W,MATCH($B$3,'Competitor Comparison Data'!$D:$D,0)+ROWS($A$8:$A8)-1),"No Match")
So it skipped over V:V and went to W:W. Additionally, when I add a second column, the first added column changes from W:W to X:X.
Once I add a column, formulas in existing columns should not change.
So two issues.
1. The first column added is not starting with the correct reference column; its skipping over V:V
2. Every new column added changes the reference column of all the other added columns. If I added 3 columns, the order of my last 4 columns would be as follows:
=IFERROR(INDEX('Competitor Comparison Data'!U:U,MATCH($B$3,'Competitor Comparison Data'!$D:$D,0)+ROWS($A$8:$A8)-1),"No Match") Correct Column
=IFERROR(INDEX('Competitor Comparison Data'!Y:Y,MATCH($B$3,'Competitor Comparison Data'!$D:$D,0)+ROWS($A$8:$A8)-1),"No Match")
=IFERROR(INDEX('Competitor Comparison Data'!Z:Z,MATCH($B$3,'Competitor Comparison Data'!$D:$D,0)+ROWS($A$8:$A8)-1),"No Match")
=IFERROR(INDEX('Competitor Comparison Data'!AA:AA,MATCH($B$3,'Competitor Comparison Data'!$D:$D,0)+ROWS($A$8:$A8)-1),"No Match")
This problem arose from this thread: https://www.mrexcel.com/forum/excel...mulas-over-right-into-new-column-added-4.html
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("C57")
ws.Range(.ListColumns(.ListColumns.Count - 1).DataBodyRange, .ListColumns(.ListColumns.Count).DataBodyRange).FillRight
End With
End With
The fill command is not behaving correctly. When I click the button to add a new column, the new column does not fill with the correct column starting point.
Here are the reference column formulas:
=IFERROR(INDEX('Competitor Comparison Data'!T:T,MATCH($B$3,'Competitor Comparison Data'!$D:$D,0)+ROWS($A$8:$A8)-1),"No Match")
=IFERROR(INDEX('Competitor Comparison Data'!U:U,MATCH($B$3,'Competitor Comparison Data'!$D:$D,0)+ROWS($A$8:$A8)-1),"No Match")
Here is the new column formula that is filled into the new column when the button is clicked:
=IFERROR(INDEX('Competitor Comparison Data'!W:W,MATCH($B$3,'Competitor Comparison Data'!$D:$D,0)+ROWS($A$8:$A8)-1),"No Match")
So it skipped over V:V and went to W:W. Additionally, when I add a second column, the first added column changes from W:W to X:X.
Once I add a column, formulas in existing columns should not change.
So two issues.
1. The first column added is not starting with the correct reference column; its skipping over V:V
2. Every new column added changes the reference column of all the other added columns. If I added 3 columns, the order of my last 4 columns would be as follows:
=IFERROR(INDEX('Competitor Comparison Data'!U:U,MATCH($B$3,'Competitor Comparison Data'!$D:$D,0)+ROWS($A$8:$A8)-1),"No Match") Correct Column
=IFERROR(INDEX('Competitor Comparison Data'!Y:Y,MATCH($B$3,'Competitor Comparison Data'!$D:$D,0)+ROWS($A$8:$A8)-1),"No Match")
=IFERROR(INDEX('Competitor Comparison Data'!Z:Z,MATCH($B$3,'Competitor Comparison Data'!$D:$D,0)+ROWS($A$8:$A8)-1),"No Match")
=IFERROR(INDEX('Competitor Comparison Data'!AA:AA,MATCH($B$3,'Competitor Comparison Data'!$D:$D,0)+ROWS($A$8:$A8)-1),"No Match")
This problem arose from this thread: https://www.mrexcel.com/forum/excel...mulas-over-right-into-new-column-added-4.html