简体   繁体   中英

Copy all formulas when inserting new row in Excel worksheet

I want to copy all formulas when inserting a new row in the Excel worksheet. I have some calculation formulas and I am taking some values from another Excel file.

Formulas I am using in this Excel worksheet are as follows:

  1. =IFERROR(VLOOKUP(C4,'list.xlsx]Sheet1'!$A$4:$L$261,3,FALSE),"")

  2. =IFERROR(G6*F6,"")

I googled for a solution. I got 2 ideas.

one to make a table with these data. I tried this one. Formula no:1 worked perfectly. But 2nd formula didn't copy to next line.

The second one to use a VBA code. which works only one time. When open excel next time I have to create VBA code again. also, it needs to click in between cells to create next row.

I want to create a new row when right click on the sl no(leftmost column) and click "insert".

Please help.

Sorry im new in SO but i want to help you:

  1. You using conditional blocking for example : $A$4:$L$261
  2. =IFERROR(G6*F6,"") doesnt copy anything
  3. In VBA you got function PasteSpecial whats copeing a formulas from cell, here some ex. of using that:

     With Worksheets("YourWorksheet_name") .Range("Your_cell_input").Copy .Range("Your_cell_output").PasteSpecial Operation:=xlPasteSpecialOperationAdd End With
  4. If i good understand u want a maro what pasting a forulas when new rod is added. I recommend to use something like this:

    Let's make a demo that You have formulas on colmn C to copy that(its affecting column A)

     Private Sub Worksheet_Change(ByVal Target As Range) If Target.Column = ActiveCell.Column Then refRow = Target.Row - 1 thisRow = Target.Row Range("C" & refRow).Copy Range("B" & thisRow) End If End Sub
  5. Anyway please add some more code what u have or screenshoots what u expecting

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM