Home > database >  Copy from Column A (Formula) and paste as Values in Column B only in Column B Blanks
Copy from Column A (Formula) and paste as Values in Column B only in Column B Blanks

Time:10-07

I believe my problem is fairly simple, but I searched the solution for hours and found nothing... And I'm too much of a newbie in JavaScript to try and adapt the solutions of relatively similar problems to solve mine.

I'm building a sheet to register inspections on cars, and I need the car location registered in it. I have an internal source of data that display actual location for each of them. I'm pulling information from that dynamic source.

The problem is if the inspection ocurred in Location A and the car changed to Location B, I'll pull the location B. So I believe I need a Google Sheets macro and schedule it to every hour copy the info of this dynamic source and paste it as values on the reccently added car inspections:

Image showing Column A with a few missing blank values and Column B completely filled

For the rows that are Blank in Column A I need to copy the values in Column B and paste them as Text in Column A.

There's a demo sheet here below if needed...

https://docs.google.com/spreadsheets/d/1ZFBlDFb0gzyjm6CR4BwiYyes7lMpC5GzqgzSl9XppmA/edit?usp=sharing

Thanks a lot for the attention guys!

CodePudding user response:

Try

function copyBtoA(){
  var sh = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
  var data = sh.getRange(1,1,sh.getLastRow(),2).getValues()
  var result=[]
  for (var i=0;i<sh.getLastRow();i  ){
    if (data[i][0] == ''){
      result.push([data[i][1]])
    }
    else{
      result.push([data[i][0]])
    }
  }
  sh.getRange(1,1,result.length,result[0].length).setValues(result)
}
  • Related