VBA Table help - column rename +

gsinkinson

New member
Joined
Jul 11, 2017
Messages
1
Reaction score
0
Points
1
I am working with a table with several columns of numbers:

Test1.GIF

I want to add several more columns to hold various calculations.

I can add a new blank column with VBA using:
Sub AddNext()
' Add new column to table
Dim ws As Worksheet
Set ws = ActiveSheet
ws.ListObjects("Table1").ListColumns.Add
End Sub


I would like to rename the column header in E1 to Rng,
add a calculation in E2 of =D2-A2,

Test2.GIF
I can add the calculation with the following but I don't
know how to rename the column header for column E:

Sub AddRng()
' Add number range to table
Range("E2").Select
ActiveCell.FormulaR1C1 = "=RC[-1]-RC[-4]"
End Sub


Then, I'd like to convert the formulas in column E to values.

Test3.GIF

I then will add more columns and calculations and convert them to values.
Can anyone provide the simplest way to rename the column header,
and then convert formulas to values?
 
For example:

Code:
Sub AddNext()
   ' Add new column to table
   Dim ws As Worksheet
   Set ws = ActiveSheet
   Dim lc As ListColumn
   Set lc = ws.ListObjects("Table1").ListColumns.Add
   lc.Range(1) = "Header"
   lc.DataBodyRange.FormulaR1C1 = "=RC[-1]-RC[-2]"
End Sub
 
Back
Top