0
votes

I built a tracking sheet in Microsoft Excel and later for sharing and work simultaneously I esport it in Google Sheet. I implement this code to a button to save the data I entered in a particular sheet to another one:

Sub SaveInvoice()
    Dim Rng As Range, TargetRow As Long
    Set Rng = Range("C3,C5,C7,C9,C11")
    If Application.WorksheetFunction.CountA(Rng) < Rng.Cells.Count Then
        MsgBox ("Please fill in empty cells before saving")
    Exit Sub
    End If
    With Sheets("Invoices")
        TargetRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
        .Range("A" & TargetRow).Resize(, 5) = Array(Rng.Cells(1), Rng.Cells(3), Rng.Cells(5), Rng.Cells(7), Rng.Cells(9))
    End With
    Rng = "": Set Rng = Nothing:
End Sub

but I tried to impliment this code in google sheets for same reason but I have a problem because it saves in Invoices cell A4 only

this is the code:

function copy() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s1 = ss.getSheetByName('New Inv Entry');
  var Properties = PropertiesService.getScriptProperties();
  var lastrow = Properties.getProperty('lastrow');
  if(lastrow==null) lastrow=1;
  else lastrow = parseInt(lastrow);
  Properties.setProperty('lastrow',(lastrow+1));
  var v = s1.getRange('A'+lastrow).getValue();
  ss.getSheetByName('Invoices').getRange('A4').setValue(v);
};

any help please?

2

2 Answers

0
votes

Shouldn't ss.getSheetByName('Invoices').getRange('A4').setValue(v); be ss.getSheetByName('Invoices').getRange('A' + lastrow).setValue(v); instead?

0
votes

Hereunder I am posting the function that I edit. The problem is when this function is executed, the data entered in New Inv Entry didn't goes to last row but it goes to a row that it have data already in it.

function copy() { var ss = SpreadsheetApp.getActiveSpreadsheet();

var s1 = ss.getSheetByName('New Inv Entry');

var Properties = PropertiesService.getScriptProperties();

var lastrow = Properties.getProperty('lastrow');

if(lastrow==null) lastrow=1;

else lastrow = parseInt(lastrow);

Properties.setProperty('lastrow',(lastrow+1));

var v = s1.getRange('C3:G11').getValue();

ss.getSheetByName('Invoices').getRange('A' + lastrow).setValue(v);

};