Script Assistance to Add New Line & Copy formulas

yvettew78

New Member
Joined
Aug 23, 2020
Messages
34
Platform
  1. Windows
  2. Web
Hi Guys

I am trying to work out a script so that when I click on the PLUS Button I have created it inserts a new row and inserts the formulas that relate to it. Please see a screenshot of the sheet.

Capture.PNG


At the moment the script I have running is as follows:-

function insertRowsAfter() {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var s = ss.getActiveSheet()
var cell = s.getActiveCell()
var row = cell.getRow()

var num = Browser.inputBox("Enter No. of rows:")
s.insertRowsAfter(18,1)
}


Cell B18 is a dropdown field, as follows:-
Capture2.PNG


B18 also has a reset / clear cell formula using a script. The script is as follows(:-
function ClearCells() {
var sheet = SpreadsheetApp.getActive().getSheetByName('Calculator');
sheet.getRange('B7').setValue('Select Panel');
sheet.getRange('B8').setValue('Select Mounting Equipment');
sheet.getRange('B9').setValue('Select Inverter');
sheet.getRange('B10').setValue('Select Smart Meter');
sheet.getRange('B13').setValue('Select Extras');
sheet.getRange('B14').setValue('Select Extras');
sheet.getRange('B15').setValue('Select Extras');
sheet.getRange('E3').setValue('Select');
sheet.getRange('E4').setValue('Select');
sheet.getRange('E5').setValue('Select');
sheet.getRange('C8').setValue('=ROUNDUP(C7/6,0)');
sheet.getRange('C7').clearContent();
sheet.getRange('C9:C27').clearContent();

}

Cell D18 formula: =IFERROR(VLOOKUP(B18,Extras!A5:B24,2,FALSE),0)
Cell E18 formula: =+C18*D18

If someone can help with how I keep the formatting when I run the script to enter a new row, that would be awesome.

Thank you
 

Attachments

  • 1598239747965.png
    1598239747965.png
    38.1 KB · Views: 29

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi Yvette
When you make a new line have you tried a copy&paste for the line above? Either for a specific range or cell by cell in a loop.
A table is another option, when you add a line to a table the formulas and formats automatically get repeated in the new row
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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