简体   繁体   中英

Automatically copy information once text in cell was changed

I need some help from the experts here.

Please take a look at this spreadsheet: https://docs.google.com/spreadsheets/d/1tSl8LxhLGoQMVT_83Ev4jMu_Fo1AW8lN6N8Yw8kX44U/edit#gid=640017957

Here is the story (in short):

Our company deals with many different sellers of e-commerce businesses that want to sell their business to new owners. For each seller, we have a specific sheet (seller A, seller B, seller C in the example spreadsheet above) where we fill out various data, including the last action and next action that we took/need to take when handling the communication regarding the sell of the business with each of our potential buyers. We try to find an easy way to automatically store the data that we fill out in the “last step” column so that every time we update a cell in this column, the data will be automatically copied to a sheet that store all the communication history with each buyer for each deal.

I thought about creating a tab such as the “all actions” sheet in the example spreadsheet above, where every time we update the data in the “last action” column, a new row will be automatically added to the “all actions” sheet with the relevant data shown there.

Is there any way to achieve this goal? If not, will you recommend a different method to get similar results so that we can automatically store (and see once needed) all the data that was entered in the past in the “last action” column?

You can use triggers to do this.

In your sheet, click Tools > Script Editor. In the script editor, click Edit -> Current Project Triggers

In that window, in the lower right, there is a button to "Add Trigger".

When you add the trigger set the "Select Event Type" to "On Change". Reference the function you wish to run that will do the work of adding the information.

You will need to write the JavaScript function (in the script editor) to do the insert.

If you are not familiar with JavaScript and using it to work with Google Sheets, the learning curve isn't very steep to do this basic thing. I recommend digging in. The power you will wield with your spreadsheets is well worth the time.

You need to use Google Apps Script and the onEdit trigger in particular.

Try this:

function onEdit(e) {

  var row = e.range.getRow();
  var col = e.range.getColumn();
  if ( e.source.getActiveSheet().getName() != "All actions" && row>1 && col==2 ){
     s_name = e.source.getActiveSheet().getName();
     b_name = e.source.getActiveSheet().getRange(row,1).getValue();
     a_taken = e.source.getActiveSheet().getRange(row,2).getValue();
     e.source.getSheetByName("All actions").appendRow([s_name,b_name,a_taken,new Date()])
  }
}

In order to use this function you need to go to the Spreadsheet file menu; click on Tools => Script editor , clear the code.gs file and copy the aforementioned code snippet. Then, everytime a seller edits the last action column the relevant information will be appended to the All actions sheet.

Try this:

function onEdit(e) {
  var sh=e.range.getSheet();
  var s_name=sh.getName();
  if ( s_name!= "All actions" && e.range.rowStart>1 && e.range.columnStart==2 ){
    values=sh.getRange(e.range.rowStart,1,1,2).getValues()[0];
    e.source.getSheetByName("All actions").appendRow([s_name,values[0],values[1],new Date()])
  }
}

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