Log File CopyTo Function Gives REF! Error With VLOOKUP Functions.

huangapple go评论49阅读模式
英文:

Log File CopyTo Function Gives REF! Error With VLOOKUP Functions

问题

I'm attempting to capture data and have it be stored as log files. The cells in the original data contain VLOOKUP formulas with absolute references to a sheet called "Index". I'm able to copy everything over, but the destination cells with VLOOKUP show up as a #REF! error saying "Unresolved sheet name 'Index'". I believe this error has something to do with renaming sheets from "Copy of...[name]" to "[name]". How do I work around this?

var ss = SpreadsheetApp.openById(''); var sheet = ss.getSheetByName('Log'); var index = ss.getSheetByName("Index"); sheet.copyTo(log_file); index.copyTo(log_file); log_file.deleteSheet(log_file.getSheetByName('Sheet1')); log_file.getSheetByName("Copy of Log").setName("Log"); log_file.getSheetByName("Copy of Index").setName("Index");

This error can be resolved by entering edit mode in the cells and pressing enter, but it's not as automated as I'd like it to be.

英文:

I'm attempting to capture data and have it be stored as log files. The cells in the original data contain VLOOKUP formulas with absolute references to a sheet called "Index". I'm able to copy everything over, but the destination cells with VLOOKUP show up as a #REF! error saying "Unresolved sheet name 'Index'". I believe this error has something to do with renaming sheets from "Copy of...[name]" to "[name]". How do I work around this?

var ss = SpreadsheetApp.openById('');
var sheet = ss.getSheetByName('Log');
var index = ss.getSheetByName("Index");
sheet.copyTo(log_file);
index.copyTo(log_file);


log_file.deleteSheet(log_file.getSheetByName('Sheet1'));
log_file.getSheetByName("Copy of Log").setName("Log");
log_file.getSheetByName("Copy of Index").setName("Index");

This error can be resolved by entering edit mode in the cells and pressing enter, but it's not as automated as I'd like it to be.

答案1

得分: 0

以下是您要翻译的代码部分:

function test() {
  try {
    let spread = SpreadsheetApp.getActiveSpreadsheet();
    let sheet1 = spread.getSheetByName("Sheet1");
    let sheet2 = spread.getSheetByName("Sheet2");
    spread = SpreadsheetApp.create("Testxxx");
    sheet2 = sheet2.copyTo(spread);
    sheet2.setName("Sheet2");
    sheet1 = sheet1.copyTo(spread);
    spread.deleteSheet(spread.getSheetByName("Sheet1"));
    sheet1.setName("Sheet1");
    sheet1.activate();  // required to move a sheet
    spread.moveActiveSheet(1);
    SpreadsheetApp.flush();
  }
  catch(err) {
    console.log(err);
  }
}

希望这对您有所帮助。

英文:

What you need to do is copy the sheet containing the lookup table first, rename it and then the other sheets. In my test case Sheet2 contains the lookup table. Not sure if the flush() is need but doesn't hurt.

function test() {
  try {
    let spread = SpreadsheetApp.getActiveSpreadsheet();
    let sheet1 = spread.getSheetByName("Sheet1");
    let sheet2 = spread.getSheetByName("Sheet2");
    spread = SpreadsheetApp.create("Testxxx");
    sheet2 = sheet2.copyTo(spread);
    sheet2.setName("Sheet2");
    sheet1 = sheet1.copyTo(spread);
    spread.deleteSheet(spread.getSheetByName("Sheet1"));
    sheet1.setName("Sheet1");
    sheet1.activate();  // required to move a sheet
    spread.moveActiveSheet(1);
    SpreadsheetApp.flush();
  }
  catch(err) {
    console.log(err);
  }
}

huangapple
  • 本文由 发表于 2023年4月11日 04:09:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/75980352.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定