VBA for adding data to new row in table whilst retaining formula?

bert1984

New Member
Joined
Jan 19, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi!

I'm new to the forum and was wondering if someone out there could give me a little guidance.

I recently watched the linked Youtube video which detailed how to add a new line containing data into a table using a macro button. Whilst the video was great and was incredibly helpful I am still struggling with one thing related to this, how to add data to a table with its corresponding formula.


For example, in the video when you use the formula "myRow.Range(1)=Range("B2")" this takes the information as it appears in the cell and enters it exactly, even if there was formula in the cell. Essentially it pastes values and not formulae.

Is there a way to do this using the same code format as in the video or do I need to start from scratch?

Any help would be greatly appreciated.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Welcome to the forum. :)

Formulas in a table should automatically fill down to new rows without you having to code them, or did I misunderstand your question?
 
Upvote 0
Hi Rory,

Thanks for the quick reply.

I understand that tables can automatically copy formula down however this isn't the case for what I am doing.

In the below image if I were to change the discount in the table on the left (i.e. the Quotation) then nothing would happen as only values have been entered from the table on the right.

What I want to achieve is if I click the "Add To Quote" button, all the cells from the table on the right are entered into the table on the left including their formulae. This means that if I should want to change a customers discount on a variety of items, I can do it on the table on the left easily.

1705669637057.png


The current VBA code i am using is: -

Private Sub cmdAdd_Click()
Dim myRow As ListRow
Dim introws As Integer

introws = ActiveWorkbook.Worksheets("Quotation Sheet").ListObjects("DATA").ListRows.Count
Set myRow = ActiveWorkbook.Worksheets("Quotation Sheet").ListObjects("DATA").ListRows.Add(introws)

myRow.Range(1) = Range("I2")
myRow.Range(2) = Range("J2")
myRow.Range(3) = Range("K2")
myRow.Range(4) = Range("L2")
myRow.Range(5) = Range("M2")
myRow.Range(6) = Range("N2")
myRow.Range(7) = Range("O2")

End Sub


Thanks again for any help :D
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,223
Members
452,620
Latest member
dsubash

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