Home > Back-end >  Drop down list should be automated to copy and paste
Drop down list should be automated to copy and paste

Time:10-20

Lets say I selected Funded in drop down list located in C2 than I would like the value of B2 copied to A2

There are numbers in the column UPCOMING INCOME and drop down list in the next column. When we choose in drop down Payed (PENDING, PAYED, PAUSED) it should copy the number from the Upcoming income column and paste to column FUNDED. enter image description here

CodePudding user response:

Moving F to A

function onEdit(e) {
  const sh = e.range.getSheet();
  if(sh.getName() == "Your Sheet Name" && e.range.columnStart == 8 && e.range.rowStart > 1 ) {
    e.range.offset(0,-7).setValue(e.range.offset(0,-2).getValue());
  }
}

CodePudding user response:

This should theoretically do what you're asking it to do, you just need to set a trigger for 'on edit' in the triggers tab when setting up your script.

function someFunction(){
  //Gets the spreadsheet with the name you specified
  var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet4')
  //Creates a 2D-Array of values based on the range you specify
  var dataRange = ss.getRange(2,6,ss.getLastRow()-1,3).getValues()
  //Runs through the 2D-array, checking every value for a match
  for(var i = 0; i < dataRange.length; i   ){
    for(var j = 0; j < dataRange[i].length; j  ){
      //If there is a match, pastes the value from the 'Upcoming Income' column to the 'Funded' column
      dataRange[i][j] == 'Payed' ? ss.getRange('A' (i 2)).setValue(dataRange[i][0]) : null
    }
  }
}

This is at least how I would solve it, but I'm sure there are many other quicker more elegant ways of doing so. You will have to make adjustment so that it will work with your spreadsheet, but I believe they should be fairly simple. If there is an error, please let me know, and I'll do my best to fix it.

In the future, please do what @Cooper recommended and make sure your question is more clear in what it is asking, and please attempt to code it yourself first before asking for help from others.

  • Related