Category and store it in the variable "Categoria" Subcategory and store it in the variable "Subcategoria" Installments and store it in the variable "Parcelado" Value and store it in the variable "Valor" Month and store it in the variable "Mês" Year and store it in the variable "Ano" Example of chosen responses:
Category: "Moradia" Subcategory: "Energia" Installments: 3 Value: 300 Month: Dezembro Year: 2025 I want to insert this information into the SHEET "Despesas Parceladas" in the following way:
Category Subcategory Installments Value Month Year Moradia Energia 1/3 100 Dezembro 2025 Moradia Energia 2/3 100 Dezembro 2025 Moradia Energia 3/3 100 Dezembro 2025 My idea to solve this problem was to make an HTTP request webhook to access my spreadsheet's script, and the script would perform the desired task, but nothing happens!! 😦
The solution was to create a new tab where all the information I collected here is inserted.
Then I created a script within Google Sheets that triggers whenever the spreadsheet is accessed or opened, which takes the row and moves it to the other tab with the correct results.
// Itera sobre as linhas da aba de origem (ignorando o cabeçalho) for (let i = 1; i < dados.length; i++) { const linha = dados[i]; const categoria = linha[0]; // Coluna "Categoria" const subcategoria = linha[1]; // Coluna "Subcategoria" const parcelado = linha[2]; // Coluna "Parcelado" const valorTotal = linha[3]; // Coluna "Valor" const mesInicial = linha[4]; // Coluna "Mês" const anoInicial = linha[5]; // Coluna "Ano"
// Calcula o valor de cada parcela const valorParcela = valorTotal / parcelado;
// Cria uma nova linha para cada parcela for (let j = 1; j <= parcelado; j++) { // Calcula o mês e ano da parcela const dataParcela = calcularMesAnoParcela(mesInicial, anoInicial, j - 1);
const novaLinha = [ categoria, subcategoria, ${j}/${parcelado}, // Formato "X/Y" para a coluna "Parcelado" valorParcela, dataParcela.mes, dataParcela.ano ]; novasLinhas.push(novaLinha); // Adiciona a nova linha ao array }
// Marca a linha para ser deletada linhasParaDeletar.push(i + 1); // +1 porque os índices das linhas começam em 1 }
// Adiciona as novas linhas à aba de destino if (novasLinhas.length > 0) { abaDestino.getRange(abaDestino.getLastRow() + 1, 1, novasLinhas.length, novasLinhas[0].length).setValues(novasLinhas); }
// Deleta as linhas processadas da aba de origem (da última para a primeira) for (let i = linhasParaDeletar.length - 1; i >= 0; i--) { abaOrigem.deleteRow(linhasParaDeletar[i]); }
Logger.log("Processo concluído. As despesas parceladas foram transferidas e as linhas importadas foram deletadas."); }
// Função para calcular o mês e ano da parcela function calcularMesAnoParcela(mesInicial, anoInicial, incremento) { const meses = [ 'janeiro', 'fevereiro', 'março', 'abril', 'maio', 'junho', 'julho', 'agosto', 'setembro', 'outubro', 'novembro', 'dezembro' ];
// Encontra o índice do mês inicial let indiceMes = meses.indexOf(mesInicial.toLowerCase());
// Calcula o novo mês e ano const novoIndiceMes = indiceMes + incremento; const novoAno = anoInicial + Math.floor(novoIndiceMes / 12); const novoMes = meses[novoIndiceMes % 12];