VBA add formula to last column of table

Sleeplol

Board Regular
Joined
Apr 10, 2019
Messages
194
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hey Everyone,

My Table's columns are updated via userform and rows via query. I have the same unlocked formula that runs across the entire table and future columns and rows.

How would you auto add the formula to the next adjacent column when it is created?

Currently fumbling with the below. Would it be better to reference the table so it's not so static?

VBA Code:
Sub ColumnFillFormula()
Dim last_Col As Long, last_Row As Long

last_Col = Cells(221, Columns.Count).End(xlToLeft).Column
last_Row = Cells(Rows.Count, last_Col).End(xlUp).Row
Range(Cells(221, last_Col + 1), Cells(last_Row, last_Col + 1)) = "=IFNA(INDEX(CVM!$B$2:$AZ$200,MATCH($AD221,CVM!$A$2:$A$200,0),MATCH(AE$220,CVM!$B$1:$AZ$1,0)),"")"
End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,213,534
Messages
6,114,188
Members
448,554
Latest member
Gleisner2

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