Macro Outputting Blank Cells

29 views
Skip to first unread message

Taylor Wagner

unread,
Sep 28, 2023, 6:11:29 PM9/28/23
to Google Apps Script Community
I'm running a macro in which I take the sum of values in cells E29 and F29, and paste the sum into G29. Then, it copies G29 and pastes it as a value only in F29. The last step is deleting the contents of G29. 

I set up the same macro on 6 different sheets and it works great on 4 of them, but on 2 of them it outputs a blank cell in F29 and I can't tell why. 

I've tried making a copy of the 2 problematic sheets and doing the same macro but the same result happens. I have also tried copying the sum in G29 and pasting it on itself as a value only before pasting it into F29 but I also had the same result. Another thing I tried was running the macro without the final step of deleting the G29 contents but the F29 cell still came out blank. 

Help?

Keith Andersen

unread,
Sep 28, 2023, 6:13:55 PM9/28/23
to google-apps-sc...@googlegroups.com
Can you share your sheet with us or at least the macro code that you're using?

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/61464be2-235c-4f8d-815c-f05e4ef4f5ddn%40googlegroups.com.

Taylor Wagner

unread,
Sep 28, 2023, 6:19:51 PM9/28/23
to Google Apps Script Community
The sheet is confidential but here is the code:

function test() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('G29').activate();
spreadsheet.getCurrentCell().setFormula('=SUM(E29:F29)');
spreadsheet.getRange('F29').activate();
spreadsheet.getRange('G29').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
spreadsheet.getRange('G29').activate();
spreadsheet.getActiveRangeList().clear({contentsOnly: true, skipFilteredRows: true});
};

Keith Andersen

unread,
Sep 28, 2023, 6:38:14 PM9/28/23
to google-apps-sc...@googlegroups.com
Try;

const wbk = SpreadsheetApp.getActiveSpreadsheet();


const ss = wbk.getActiveSheet();


const value1 = ss.getRange("E29").getValue();

const value2 = ss.getRange("F29").getValue();

const sumValues = value1 + value2;


ss.getRange("F29").setValue(sumValues);


Keith Andersen

unread,
Sep 28, 2023, 7:55:42 PM9/28/23
to google-apps-sc...@googlegroups.com
Sorry... Forgot to put that into function. Try this:

function gather_set(){

Keith Andersen

unread,
Sep 28, 2023, 10:49:51 PM9/28/23
to google-apps-sc...@googlegroups.com

Taylor Wagner

unread,
Sep 28, 2023, 10:54:27 PM9/28/23
to Google Apps Script Community
Thank you Keith for taking some time to look into this. I'm actually wanting to do this function on a larger scale moving all the way down through row 46. Let me make a copy of the spreadsheet and redact the sensitive information so I can share it with you and you can see more first-hand

Taylor Wagner

unread,
Sep 28, 2023, 11:12:36 PM9/28/23
to Google Apps Script Community
I tried running the code that you provided for me in the shared spreadsheet and I still got the same result..... could it be because of other existing things in the sheet?

Keith Andersen

unread,
Sep 28, 2023, 11:31:02 PM9/28/23
to google-apps-sc...@googlegroups.com
Your location could be a factor. Certain app script code is world hemisphere dependent.


Keith Andersen

unread,
Sep 29, 2023, 12:26:19 AM9/29/23
to google-apps-sc...@googlegroups.com
Try opening Sheets in a different browser like Chrome or Firefox

Keith Andersen

unread,
Sep 30, 2023, 12:41:18 PM9/30/23
to google-apps-sc...@googlegroups.com
Has any of this helped to resolve your problem?
Reply all
Reply to author
Forward
0 new messages