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: 3

Some videos you may like

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

rondeondo

Board Regular
Joined
Aug 15, 2012
Messages
156
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
 

Watch MrExcel Video

Forum statistics

Threads
1,127,332
Messages
5,624,053
Members
416,007
Latest member
csf

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
Top