Search code examples
google-sheetsgoogle-sheets-apigoogle-sheets-macros

Submit data from cells on google sheet A to Sheet B on button press


I cant use forms to power the data collection into Google sheets due to limitations of forms and dynamic drop downs. However, I would like to create a collection set of boxes (like a form) in sheet A and have a submit button which pumps the data into a row on sheet B.

So for example:

Sheet A - in Cell A1 = Name : A3 = Group : A5 = System.

Each cell on sheet A which is listed above is a drop-down which is dynamically linked to each other. I then need to paste these entries into Sheet B into the next available row.

So sheet B would have A1 = Bob B1 = Team 2 C1 = New system and so on.

Cheers


Solution

  • Sorry the English

    See if the following script can help you!

        function transferdata() {
    
    var ui = SpreadsheetApp.getUi();
      var result = ui.alert(
      '***          ATTENTION          ***', 
      'Do you want to "SAVE" this information on the "Sheet B" tab',
      ui.ButtonSet.YES_NO);
      if (result == ui.Button.YES) {
    
      var tab1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet A");
    
      var Name = tab1.getRange("B1").getValue();
      var Group = tab1.getRange("B3").getValue();
      var System = tab1.getRange("B5").getValue();
    
    
      var tab2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet B");
      var lr = tab2.getLastRow() + 1;
    
      tab2.getRange(lr, 1).setValue(Name);
      tab2.getRange(lr, 2).setValue(Group);
      tab2.getRange(lr, 3).setValue(System);
    
    
      tab1.getRange("B1").clearContent();
      tab1.getRange("B3").clearContent();
      tab1.getRange("B5").clearContent();
    
    
      ui.alert ('Information was successfully SAVED on the DATABASE tab');
       } else {
         ui.alert ('The information "NOT" has been saved!');
    
     }
    }
    

    Sidney