Inventario de existencias de hojas de Google
Hola a todos,
Me dirijo a usted porque no puedo hacer que mi código funcione en Google Sheets. El objetivo del programa es poder seguir la evolución del stock de las distintas referencias cotizadas. Para ello, tan pronto como se realice un cambio, se debe almacenar la fecha y el estado del stock en una casilla adicional (de ahí las referencias solas en la parte inferior de la hoja). Por el momento, el código hace esto: cuando ingresa 1 o -2, por ejemplo, en la columna "+/-", el stock y el consumo se actualizan, luego la columna "+/-" se restablece a cero. El código está comentado para que puedas entender mi enfoque. Gracias a cualquiera que pueda ayudarme, estoy luchando mucho para hacer el programa.
function onEdit(){ if(SpreadsheetApp.getActiveRange().getColumn()==4){ ///things only happen if the "+/-" column is changed for (var i in 2,403){ var cellTest = SpreadsheetApp.getActive().range.getCell(i,4); /// we retrieve each box of the "+/-" column if( cellTest != 0){ //// we test if it change var k =408+i; /// hint for date display lines var l = 2; //// index for date display columns var cellDate = SpreadsheetApp.getActive().range.getCell(k,l); while (isEmpty(cellDate)==false){ ///the goal is to put the new date next to the previous one l=l+1; } const cellDateDef = SpreadsheetApp.getActive(); cellDateDef.getRange(k,l).setValue(Date) /// on affiche la date du changement de stock const cellStock = SpreadsheetApp.range.getCell(i,5); SpreadsheetApp.range.getCell(k+1,5) = cellStock; ///in the box under the date of the change the stock status is displayed } } var spreadsheet = SpreadsheetApp.getActive(); spreadsheet.getRange('G2:G403').setValue('0'); ////we reset the "+/-" column to zero } }Aquí están las imágenes para completar y entender mi pregunta: el final de la hoja de Google
Hay dos fórmulas en las columnas:
Acción: =D2+E2
Consumo: =SI(D2<0;-D2+G2;G2)
la hoja se hace en modo de cálculo iterativo
Gracias por tu ayuda