VBA Add New Table Row & Keep Formulas

Tknowles

New Member
Joined
Apr 12, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi Team

I have a 27 column table that I am adding new rows to based on the range C2:AC2. Two issues, 1) some of my input range cells are formulas which are not getting copied to the table when running the VBA (only the values) and 2) it takes awhile for the VBA to be completed - is there a more efficient code?

Sub Addrecord()
Dim ws As Worksheet
Dim newrow As ListRow


Set ws = ActiveSheet
Set newrow = ws.ListObjects("ClientCoverage").ListRows.Add

With newrow

.Range(1) = Range("C2")
.Range(2) = Range("D2")
.Range(3) = Range("E2")
.Range(4) = Range("F2")
.Range(5) = Range("G2")
.Range(6) = Range("H2")
.Range(7) = Range("I2")
.Range(8) = Range("J2")
.Range(9) = Range("K2")
.Range(10) = Range("L2")
.Range(11) = Range("M2")
.Range(12) = Range("N2")
.Range(13) = Range("O2")
.Range(14) = Range("P2")
.Range(15) = Range("Q2")
.Range(16) = Range("R2")
.Range(17) = Range("S2")
.Range(18) = Range("T2")
.Range(19) = Range("U2")
.Range(20) = Range("V2")
.Range(21) = Range("W2")
.Range(22) = Range("X2")
.Range(23) = Range("Y2")
.Range(24) = Range("Z2")
.Range(25) = Range("AA2")
.Range(26) = Range("AB2")
.Range(27) = Range("AC2")
End With


End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
First, copy your range . . .

VBA Code:
Range("C2:AC2").Copy

Then paste formulas . . .

VBA Code:
newrow.Range.PasteSpecial xlPasteFormulas

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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