简体   繁体   English

按同一行和上面的行中的条件返回单元格值

[英]Return cell value by criteria in same row AND row above

This is a very complicated question.这是一个非常复杂的问题。 I'm not even sure if what I'm hoping for is possible, but I have been surprised many times before.我什至不确定我所希望的是否可能,但我之前曾多次感到惊讶。 Here we go....开始了....

Here are the links to the two spreadsheets I am modeling my situation after: John Doe and Jane Doe .以下是我正在模拟我的情况的两个电子表格的链接: John DoeJane Doe

In these spreadsheets, I recently set up a script for making dynamic dropdown lists according to this video: DYNAMIC DEPENDENT DROP DOWN LISTS IN GOOGLE SPREADSHEETS .在这些电子表格中,我最近根据以下视频设置了一个用于制作动态下拉列表的脚本: DYNAMIC DEPENDENT DROP DOWN LISTS IN GOOGLE SPREADSheets It works great for me, but there is a whole level on top of it that I need to establish.它对我很有用,但我需要在它之上建立一个完整的层次。 First and foremost, be aware that I cannot move any of the cells/rows/columns.首先,请注意我无法移动任何单元格/行/列。

In my system here, I have two individuals working on a TASK (TASK1), one a Writer and the other a Reviewer.在我的系统中,我有两个人在处理一项任务 (TASK1),一个是作家,另一个是审阅者。 The John Doe, for example, will log their task (TASK1), and in the Total line they will indicate the TASK TYPE (Write) and WRITING PARTNER (Jane Doe).例如,John Doe 将记录他们的任务 (TASK1),并在 Total 行中指明任务类型(写入)和写作伙伴(Jane Doe)。 Jane Doe will do the same and then give John Doe a score after her review in column O. The roles here could also be switched-- for example, see TASK2, where Jane Doe is the Writer this time and John Doe is the Reviewer. Jane Doe 会做同样的事情,然后在 John Doe 在 O 列的评论后给她打分。这里的角色也可以转换——例如,参见 TASK2,这次 Jane Doe 是作家,John Doe 是审稿人。

The difference is the formula in column F under SCORE, where it populates differently according to the TASK TYPE specified in the individual's sheet: If it is specified as a Review task for that person, it will populate with the score their Reviewer gave;不同之处在于 SCORE 下 F 列中的公式,根据个人工作表中指定的 TASK TYPE 填充不同的公式:如果它被指定为该人的审查任务,它将填充其审查者给出的分数; if it is not specified as a Review task, it will be kept blank;如果未指定为Review任务,则保留为空白; if their Reviewer has not yet left a Score, it will populate the placeholder "(Score)";如果他们的审阅者尚未留下分数,它将填充占位符“(分数)”; and lastly, if it is specified as a Write task.......最后,如果它被指定为写入任务.......

....the idea is that I want it to populate with the SCORE value in column F for the task having the same TASK NAME in whoever's spreadsheet is specified in the WRITING PARTNER column. ....这个想法是,我希望它填充 F 列中的 SCORE 值,用于在 WRITING PARTNER 列中指定任何人的电子表格中具有相同 TASK NAME 的任务。 I've figured out how to dynamically import the correct spreadsheet using a VLOOKUP within an IMPORTRANGE function: IMPORTRANGE(VLOOKUP(E4,'Named Ranges'!B:D,3,FALSE),"'2019'!whateverrangeIneed")我已经想出了如何在 IMPORTRANGE 函数中使用 VLOOKUP 动态导入正确的电子表格: IMPORTRANGE(VLOOKUP(E4,'Named Ranges'!B:D,3,FALSE),"'2019'!whateverrangeIneed")

But beyond that, I haven't figured out how to return the correct value from Jane Doe's spreadsheet into John Doe's spreadsheet.但除此之外,我还没有弄清楚如何将 Jane Doe 的电子表格中的正确值返回到 John Doe 的电子表格中。 Please see my attempts in John Doe's spreadsheet.请参阅我在 John Doe 的电子表格中的尝试。 The biggest issue is that I need to use not only column A="Total" as a criteria, but also column B of the row above the total ="The TASK NAME to reference".最大的问题是,我不仅需要使用列 A="Total" 作为标准,还需要使用总数上方行的B="要引用的任务名称"。 If I could figure that out, I could paste that formula into "FORMULATOSOLVE" of the function in column F. Ultimately, the point is to be able to report an Average Score for John Doe the Writer, based on his review scores, using the formula AVERAGE(FILTER('2019'!F:F,'2019'!D:D="Write",'2019'!E:E<>"None")) .如果我能弄清楚,我可以将该公式粘贴到 F 列中函数的“FORMULATOSOLVE”中。最终,关键是能够报告作者 John Doe 的平均分数,根据他的评论分数,使用公式AVERAGE(FILTER('2019'!F:F,'2019'!D:D="Write",'2019'!E:E<>"None"))

As mentioned, I've recently used a script for the first time, so I'm not opposed to doing that here as well if needed, but I don't have the know-how to write it myself.如前所述,我最近第一次使用脚本,所以如果需要,我也不反对在这里这样做,但我不知道如何自己编写它。

Thank you immensely for any help.非常感谢您的任何帮助。

Since you have tried Apps Script I have written this simple script that does what you need.由于您尝试过 Apps Script,因此我编写了这个简单的脚本来满足您的需求。 This will work with the amount of Tasks that you want, since iterates over all the column length.这将适用于您想要的任务数量,因为迭代所有列长度。

function getScore() {

  // GET the two sheets
  var writer = SpreadsheetApp.openById('WRITER SHEET ID').getSheetByName('2019');
  var reviewer =  SpreadsheetApp.openById('REVIEWER SHEET ID').getSheetByName('2019');

  // Get the B column of each sheet
  var writerTask = writer.getRange("B2:B").getValues();
  var reviewerTask = reviewer.getRange("B2:B").getValues();

  // Variables to save data
  var writerScore = '';
  var taskName = '';

  // Iterate over every single row in column B of writer
  for (var i = 1; i < writerTask.length; i++) {

    // Check if the actual row is empty (which means is the total row)
    // and also check if the row before is not empty
    if (writerTask[i] == '' && writerTask[i-1] != ''){

      // Assign the values inside the previous row to taskName (will be TASK1)
      taskName =  writerTask[i-1].toString();

      // Get the cell where the score has to go
      writerScore = writer.getRange('F'+(i+2))

      // Iterate over the reviewers sheet
      for (var j = 1; j < reviewerTask.length; j++) {

        // Check if cell is empty and check the previous cell has the same
        // value from the one on the writers sheet
        if (reviewerTask[j-1].toString() == taskName && reviewerTask[j] == ''){ 

          // Assign the value from the cell on reviewers sheet to the cell on the writers sheet
          writerScore.setValue(reviewer.getRange('F'+(j+2)).getValue());
        }
      }
    }
  } 
}

To run the script you can set up a button on the sheet you want, see: Clickable images and drawings in Google Sheets要运行脚本,您可以在所需的工作表上设置一个按钮,请参阅: Google Sheets 中的可点击图像和绘图

if I understood it right, try:如果我理解正确,请尝试:

=ARRAYFORMULA(IFERROR(IF(D4="Write", VLOOKUP(E4&B3, 
 {IMPORTRANGE("1rrshg9qcShUCqQDEhp74aRHzcyDRgsh5IWM60Lypup8", "2019!E2:E1000")&
  IMPORTRANGE("1rrshg9qcShUCqQDEhp74aRHzcyDRgsh5IWM60Lypup8", "2019!B1:B1000"), 
  IMPORTRANGE("1rrshg9qcShUCqQDEhp74aRHzcyDRgsh5IWM60Lypup8", "2019!F2:F1001")}, 2, 0),
 IF(D4="Review", IF(O4="", "(Score)", O4), )), "no data"))

在此处输入图片说明


note to allow access beforehand you do above:请注意在您执行上述操作之前允许访问:

在此处输入图片说明

This problem has been solved.这个问题已经解决了。 The script and formula in use can be seen in the google sheets by following the links.使用的脚本和公式可以通过以下链接在谷歌表格中查看。 The script used was:使用的脚本是:

function WriterScore(projectName, importedSheet){

  // Create a set of variables
  var foundScore = false;
  var score = "";
  var data = importedSheet;

  while(foundScore == false){
    for(var i = 0; i<data.length;i++){
      if(data[i][1] == projectName){
        for(var q = i; q<data.length;q++){
          if(data[q][1] == projectName){
          }else{
            score = data[q][5]
            return score
          }
        }
      }
    }
    if(score == ""){
      return "You do not have a project by that name.";
    }
  }

  return score
}

And the final cell formula was:最终的单元格公式是:

=IF(D7="Write",WriterScore(B6,IMPORTRANGE(VLOOKUP(E7,'Named Ranges'!B:D,3,FALSE),"'2019'!A:F")),IF(D7="Review",IF(O7="","(Score)",O7),""))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM