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

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
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,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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