How to show active Google Sheets user in cell

I want to put the name of whoever is currently using my Google spreadsheet into a specific cell. The reason I need this is so I can use it with a vlookup formula to get other data based on who’s logged in.

I already wrote some Google Apps Script code that can get the username of the person who’s signed in. The script works fine and I can see the username when I check the script editor’s logs. But now I’m stuck because I can’t figure out how to take that logged information and actually put it into a cell in my spreadsheet.

Is there a way to get the script results to show up in the sheet itself instead of just in the logs?

you just need to use setValue() for writing the username to the cell. like, try SpreadsheetApp.getActiveSheet().getRange(‘A1’).setValue(username). just change ‘A1’ to the cell you want it to show up in. simple as that!

This is a common issue when moving from testing to real implementation. The other answers got setValue right, but missed something crucial - timing. Active user detection only works when the script runs, so you need to decide when to capture this info. I’d create a function that runs onOpen() to update whenever someone opens the sheet. Also, Session.getActiveUser().getEmail() can return empty for unauthorized users, so add error handling. Once setValue works, consider storing timestamps with usernames to track sheet activity better.

You’re not connecting your script to the spreadsheet. Your code probably grabs the username fine, but you need to tell it which cell to write to. Use var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); then sheet.getRange('B2').setValue(activeUser); - just swap B2 for whatever cell you want. Double-check your script has permissions to modify the sheet. I had the same problem when I started with Apps Script - logging’s easy but writing to cells needs those spreadsheet methods. Set up a trigger if you want it updating automatically when someone opens the sheet.

Check if your script runs when users open the sheet. It’s probably not triggering at all. Set up an installable trigger in the script editor instead of using onOpen(). Simple triggers don’t fire reliably for users who aren’t the sheet owner.

Apps Script’s user detection is honestly a pain with all the trigger and permission headaches.

I’d skip that mess and use Latenode instead. It monitors your Google Sheet and automatically grabs user info when someone opens or edits it. Way more reliable than fighting with onOpen triggers.

I’ve done this exact thing before - Latenode catches the activity, pulls the user details, and drops them right into your cell. No authorization drama.

Bonus: you can expand it beyond just usernames. Track timestamps, build activity reports, send alerts when certain people access the sheet.

Takes like 10 minutes to set up and actually works consistently.

Check it out: https://latenode.com