I was able to create a script to do what I needed.
I used the onEdit
function provided by Google Sheets, so the script runs whenever a cell is edited.
In order to make the script run as efficiently as possible, I check first if the cell is in a sheet in which the cells should be replaced with the default formula if empty. If it is not, the script exits. Then, I check if it is in the right range, and finally if it is not blank. If it meets all the criteria, the cell's value is replaced with the default formula. Here is the script:
function onEdit(e) {
var editRange = { // B3:AL13
top : 3,
bottom : 12,
left : 2,
right : 38
};
//Get sheet from which the event occured
var range = e.range
var sheet = range.getSheet();
var name = sheet.getName();
//Exit if sheet is not a sheet where cells should be changed
if (name != "Section 1 Homework") return;
// Exit if we're out of range
var thisRow = e.range.getRow();
if (thisRow < editRange.top || thisRow > editRange.bottom) return;
var thisCol = e.range.getColumn();
if (thisCol < editRange.left || thisCol > editRange.right) return;
//Exit if the cell is not blank
if (!range.isBlank()) return;
//Set the cell value to the default formula
range.setValue( "=if(INDEX('Section 1 Attendance'!A1:AL12, " + thisRow + ", " + thisCol + ") = \"A\", \"A\", \"\")" )
}