简体   繁体   中英

How to show an advice message if a cell is blank in google sheets?

i hope you can help me. I have this code, and i want to display an alert if the cell is blank, and also, if it is dont paste the information on my DB.


function Guardar() {
    var hojaActiva = SpreadsheetApp.getActiveSpreadsheet();
    var registro = hojaActiva.getSheetByName("Macro de Solicitud");
    var bd = hojaActiva.getSheetByName("Respuestas Macro de Solicitud");
    var valores = [
        [
            registro.getRange("c16").getValue(),
            registro.getRange("j13").getValue(),
            registro.getRange("f14").getValue(),
            registro.getRange("c4").getValue(),
            registro.getRange("c6").getValue(),
            registro.getRange("c8").getValue(),
            registro.getRange("c10").getValue(),
            registro.getRange("c12").getValue(),
            registro.getRange("c14").getValue(),
            registro.getRange("f4").getValue(),
            registro.getRange("f6").getValue(),
            registro.getRange("f8").getValue(),
            registro.getRange("f10").getValue(),
            registro.getRange("f12").getValue(),
            registro.getRange("f16").getValue()
        ]
    ];
    bd.getRange(bd.getLastRow() + 1, 1, 1, 15).setValues(valores);
}

In your sheet names 'Macro de Solicitud' add a formula in a cell that count the number of values in C16,J13,F14,etc. and compare with the number of cells. By checking the result you will find if one at least cell is blank before pasting the informations in your data base..

Alert if range is blank

function lfunko() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName("Sheet0");
  const ui = SpreadsheetApp.getUi();
  const rgl = sh.getRangeList(["c16","j13","f14","c4","c6","c8","c10","c12","c14","f4","f6","f8","f10","f12"]);
  rgl.getRanges().forEach(r => {if(r.isBlank()){ui.alert(`${r.getA1Notation()} is blank`)}});
}

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