Enter a formula in the first cell of a set column in my table with VBA

Xalova

Board Regular
Joined
Feb 11, 2021
Messages
80
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
So basicly what my problem is is that:
I have a table named "Teilbedarf". There is a column with the name "Benennung". I use a macro to delete the whole table every so often. But i need to enter a formula again in the first cell of "Benennung" after i deleted the whole table.

How do i do that via vba?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Assuming that you mean "cleared" rather than "deleted", do you mean something like the code below?

VBA Code:
Sub Xalova()
    Dim myTbl As ListObject
    Set myTbl = ActiveSheet.ListObjects("Teilbedarf")
    myTbl.DataBodyRange.Cells(1, myTbl.ListColumns("Benennung").Index).Formula = "=SUM(G7:G26)"
End Sub
 
Upvote 0
Assuming that you mean "cleared" rather than "deleted", do you mean something like the code below?

VBA Code:
Sub Xalova()
    Dim myTbl As ListObject
    Set myTbl = ActiveSheet.ListObjects("Teilbedarf")
    myTbl.DataBodyRange.Cells(1, myTbl.ListColumns("Benennung").Index).Formula = "=SUM(G7:G26)"
End Sub
i tried to run your code and substitue your Formula ("=SUM(G7:G26)") with my formula ("=[@Normteil]&" "&[@Norm]&IF(SUMPRODUCT(--([@Normteil]=Schraubenklassen))>0,"x"&[@Abmaße],"")") which sadly did not work. I do not know why tho.
 
Upvote 0
Did it put my formula in correctly?
i mean.. copy paste, no?

VBA Code:
Sub Xalova()
Dim myTbl As ListObject
    Set myTbl = ActiveSheet.ListObjects("Teilbedarf")
    myTbl.DataBodyRange.Cells(1, myTbl.ListColumns("Benennung").Index).Formula = "=[@Normteil]&" "&[@Norm]&IF(SUMPRODUCT(--([@Normteil]=Schraubenklassen))>0,"x"&[@Abmaße],"")"
End Sub
 
Upvote 0
I didn't ask about your formula that you have put in the last post. I asked if it put my formula in correctly, in other words did it put my formula in the correct cell?

I am not asking if your formula works or not as that is a different question.
 
Upvote 0
I didn't ask about your formula that you have put in the last post. I asked if it put my formula in correctly, in other words did it put my formula in the correct cell?

I am not asking if your formula works or not as that is a different question.
Yes your formula did work and it did write in the correct cell. If that answers your question
 
Upvote 0
Then your formula is incorrect and so that is a different question to how to place a formula in a cell, which you should start a new thread for (especially as I am going out for a few hours).
 
Upvote 0

Forum statistics

Threads
1,223,703
Messages
6,173,972
Members
452,540
Latest member
haasro02

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