About adding a formula when adding a row

muhittinemmi

New Member
Joined
Jun 20, 2023
Messages
19
Hello

When new line is added in below codein line 5; The formula =IF(E5<>"";C5*E5;"") in Cell F5 and =IF(E5<>"";M5;"") in cell G5

What kind of change should be made in order to be able to add automatically according to the added line information.

VBA Code:
Sub Ekle()
Dim i As Integer
s = Sheets("Teklif").[H65536].End(3).Row
Sheets("Teklif").Range("B" & s & ":H" & s).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
For i = 5 To s
Top = Top + (Sheets("Teklif").Range("H" & i) * Sheets("Teklif").Range("H" & i))
Next i
If Top = 0 Then Exit Sub
Sheets("Teklif").Range("H" & s + 1) = Round(Top, 2)
End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Book2
BCDEFGH
523002
6224801
teklif
Cell Formulas
RangeFormula
F5:F6F5=IF(E5<>"",C5*E5,"")
G5:G6G5=IF(E5<>"",M5,"")


VBA Code:
Sub Ekle()
Dim i As Integer
s = Sheets("Teklif").[H65536].End(3).Row
Sheets("Teklif").Range("B" & s & ":H" & s).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
For i = 5 To s
Top = Top + (Sheets("Teklif").Range("H" & i) * Sheets("Teklif").Range("H" & i))
Sheets("Teklif").Cells(i, "F").Formula = "=IF(E" & i & "<>"""",C" & i & "*E" & i & " ,"""")"
Sheets("Teklif").Cells(i, "G").Formula = "=IF(E" & i & "<>"""",M" & i & ","""")"
Next i
If Top = 0 Then Exit Sub
Sheets("Teklif").Range("H" & s + 1) = Round(Top, 2)
End Sub

Sheets("Teklif").Cells(i, "F").Formula = "=IF(E" & i & "<>"""",C" & i & "*E" & i & " ,"""")"
Sheets("Teklif").Cells(i, "G").Formula = "=IF(E" & i & "<>"""",M" & i & ","""")"

If you're using ; instead of , you may replace , into ;

Sheets("Teklif").Cells(i, "F").Formula = "=IF(E" & i & "<>"""";C" & i & "*E" & i & " ;"""")"
Sheets("Teklif").Cells(i, "G").Formula = "=IF(E" & i & "<>"""";M" & i & ";"""")"

Kindly give a shot, is it what you're looking for?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,843
Members
449,193
Latest member
MikeVol

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