Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
Google sheet Script issue

I'm trying to replicate a spreadsheet I saw online with modifications. The purpose of the spreadsheet is to document my Bull Put/Bear Call credit spreads. The plan is to have a dashboard sheet where I can enter the info and by clicking the add position button, it will transfer the info into the data sheet where all logs will be held. I will also be able to close positions from the dashboard page, but I have not even begun that script as of yet. The script I am putting together is.

function AddPosition() {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var dashboard = ss.getSheetByName("Dashboard");
  var data = ss.getSheetByName("Data");
  var expiration = dashboard.getRange(7, 3).getValue();
  var sym = dashboard.getRange(7, 4).getValue();
  var contracts = dashboard.getRange(7, 5).getValue();
  var type = dashboard.getRange(7, 6).getValue();
  var shortleg = dashboard.getRange(7, 7).getValue();
  var longleg = dashboard.getRange(7, 8).getValue();
  var pop = dashboard.getRange(7, 9).getValue();
  var credit = dashboard.getRange(7, 10).getValue();

if (expiration=="" ||
    sym=="" || 
    contracts=="" || 
    type=="" || 
    shortleg=="" || 
    longleg=="" || 
    pop=="" || 
    credit=="" || {
      **var ui = SpreadsheetApp.getUi(); // Same variations.**
      var response = ui.alert('Missing data','Please fill in missing values and try again.', ui.ButtonSet.OK);
      return;
}

  data.insertRowAfter(data.getLastRow());
  var lastRow = data.getLastRow();
  var now = new Date();
   data.getRange(lastRow, 1).setValue(now);
   data.getRange(lastRow, 2).setValue(sym);
   data.getRange(lastRow, 3).setValue(type);
   data.getRange(lastRow, 4).setValue(expiration);
   data.getRange(lastRow, 6).setValue(longleg);
   data.getRange(lastRow, 7).setValue(shortleg);
   data.getRange(lastRow, 9).setValue(contracts);
   data.getRange(lastRow, 10).setValue(credit);
   data.getRange(lastRow, 13).setValue(pop);

   data.getRange(lastRow-1, 33).copyTo(data.getRange(lastRow, 33));
   data.getRange(lastRow-1, 34).copyTo(data.getRange(lastRow, 34));
   data.getRange(lastRow-1, 35).copyTo(data.getRange(lastRow, 35));
   data.getRange(lastRow-1, 36).copyTo(data.getRange(lastRow, 36));
   data.getRange(lastRow-1, 37).copyTo(data.getRange(lastRow, 37));

  dashboard.getRange(7,2,1,11 ).clearContent();

}

On line 23 var ui = SpreadsheetApp.getUi(); // Same variations. I keep getting

SyntaxError:Unexpected identifier line:23 file: Code Gs

I don't know what I'm doing wrong.

Basically, I'm trying say if data is missing, an alert will fire stating "'Missing data','Please fill in missing values and try again.'"

Can anyone help?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I saw a few missing parenthesis within your if-else statement and also a few asterisks "*" on the declared var. Fixed it up and it executed properly on my end.

Try this:

if (expiration=="" ||
sym=="" || contracts=="" || type=="" || shortleg=="" || longleg=="" || pop=="" || credit=="") {
var ui = SpreadsheetApp.getUi(); //Same variations.
var response = ui.alert('Missing data','Please fill in missing values and try again.', ui.ButtonSet.OK);
return;
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!