Paste COUNTIF公式的结果,而不是公式。

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

Paste COUNTIF Formula Results, Not The Formula

问题

我已经为此努力了数小时。

我有一个脚本,每隔24小时从另一个工作表中获取值,并将其存储在一个单元格中。这样我们就可以保持一个持续更新的顺序...

像这样:

10/4/23 - 10

11/4/23 - 15

12/4/23 - 24

等等

工作得很好... 但是,我遇到的问题是,我的脚本是通过粘贴公式而不是公式的结果来工作的。所以实际上我得到的是一个不断更新的工作表,像这样...

10/4/23 - 10

11/4/23 - 10

12/4/23 - 10

有没有人知道一种方法,可以粘贴公式的输出而不是公式本身?或者甚至有一种方法可以将结果复制并粘贴为仅值?

我的脚本在这里:

  1. function addDate() {
  2. var ss = SpreadsheetApp.getActiveSpreadsheet();
  3. var sh = ss.getActiveSheet();
  4. var tz = ss.getSpreadsheetTimeZone();
  5. var d = Utilities.formatDate(new Date(), tz, 'yyyy-MM-dd');
  6. sh.appendRow([d,'=COUNTIF(currentAffiliates!C:C,"Joined")','=COUNTIF(currentAffiliates!C:C,"Rejected")']);
  7. }
英文:

Ive been wrestling with this for hours.

I have a script which every 24 hours takes the value from another sheet, and stores it into a cell. So we can keep a running order...

like

10/4/23 - 10

11/4/23 - 15

12/4/23 - 24

etc etc

Works fine....however, the problem I have is that my script works by pasting the formula, not the results of the formula. So what I actually end up with is a sheet that constantly updates itself, like....

10/4/23 - 10

11/4/23 - 10

12/4/23 - 10

Does anyone know a method whereby instead of pasting the formula, I can paste the output of the formula? Or even a method to copy the result, and paste it as value only?

My script is here;

  1. function addDate() {
  2. var ss = SpreadsheetApp.getActiveSpreadsheet();
  3. var sh = ss.getActiveSheet();
  4. var tz = ss.getSpreadsheetTimeZone();
  5. var d = Utilities.formatDate(new Date(), tz, 'yyyy-MM-dd');
  6. sh.appendRow([d,'=COUNTIF(currentAffiliates!C:C,"Joined")','=COUNTIF(currentAffiliates!C:C,"Rejected")']);
  7. }

答案1

得分: 1

  1. function addDate() {
  2. var ss = SpreadsheetApp.getActiveSpreadsheet();
  3. var sh = ss.getActiveSheet();
  4. var tz = ss.getSpreadsheetTimeZone();
  5. var d = Utilities.formatDate(new Date(), tz, 'yyyy-MM-dd');
  6. // I modiifed the below script.
  7. var [joined, rejected] = ['joined', 'rejected'].map(e => range.createTextFinder(e).matchCase(false).matchEntireCell(true).findAll().length);
  8. sh.appendRow([d, joined, rejected]);
  9. }
英文:

I believe your goal is as follows.

  • You want to put the actual values instead of the formulas of '=COUNTIF(currentAffiliates!C:C,"Joined")','=COUNTIF(currentAffiliates!C:C,"Rejected")'.

In this case, how about the following modification?

Modified script:

  1. function addDate() {
  2. var ss = SpreadsheetApp.getActiveSpreadsheet();
  3. var sh = ss.getActiveSheet();
  4. var tz = ss.getSpreadsheetTimeZone();
  5. var d = Utilities.formatDate(new Date(), tz, 'yyyy-MM-dd');
  6. // I modiifed the below script.
  7. var { joined, rejected } = ss.getRange("'currentAffiliates'!C:C").getDisplayValues()
  8. .reduce((o, [c]) => {
  9. ["joined", "rejected"].forEach(e => {
  10. if (e == c.toLowerCase()) {
  11. o[e]++
  12. }
  13. });
  14. return o;
  15. }, { joined: 0, rejected: 0 });
  16. sh.appendRow([d, joined, rejected]);
  17. }
  • When this script is run, the actual values are appended instead of the formulas of '=COUNTIF(currentAffiliates!C:C,"Joined")','=COUNTIF(currentAffiliates!C:C,"Rejected")' to the sheet.

  • In this case, I thought that the following modification might be able to be also used.

    • From

      1. var { joined, rejected } = ss.getRange("'currentAffiliates'!C:C").getDisplayValues()
      2. .reduce((o, [c]) => {
      3. ["joined", "rejected"].forEach(e => {
      4. if (e == c.toLowerCase()) {
      5. o[e]++
      6. }
      7. });
      8. return o;
      9. }, { joined: 0, rejected: 0 });
    • To

      1. var [joined, rejected] = ["joined", "rejected"].map(e => range.createTextFinder(e).matchCase(false).matchEntireCell(true).findAll().length);

References:

huangapple
  • 本文由 发表于 2023年4月19日 16:18:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76052200.html
匿名

发表评论

匿名网友

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

确定