I'm currently using a loop array function to automatically populate values, but I've encountered an issue where the array assigns an "undefined" label to blank values. Is there a way to modify this function to skip over any empty cells in my file?
function SubGroup_Update() {
var Metrics = SpreadsheetApp.openById("10Wl1B4AtdLHJXBbLbMQbSdtRyAb61biCWYpOQEEywIY"); // METRICS spreadsheet
var Data = SpreadsheetApp.getActiveSpreadsheet(); // DATA spreadsheet
var SubsMetricSheet = Metrics.getSheetByName('Sub Group Metrics'); // METRICS "Sub Group" sheet
var SubGroupDataSheet = Data.getSheetByName("The Sub Group_Numbers") // DATA "Sub Group" sheet
var SubGroupAllValues = SubGroupDataSheet.getRange(2, 1, SubGroupDataSheet.getLastRow() - 1, SubGroupDataSheet.getLastColumn()).getValues();
var SubsDataLastRow = SubGroupDataSheet.getLastRow(); // Get the number for the amount of rows with info in the DATA "Sub Group" Sheet
var FeedDataSheet = Data.getSheetByName("The Feed_Raw") // DATA "Feed" sheet
var FeedAllValues = FeedDataSheet.getRange(2, 1, FeedDataSheet.getLastRow() - 1, FeedDataSheet.getLastColumn()).getValues();
//var SubsDataRange = SubGroupDataSheet.getRange("A2:K"); // The entire range of cells in the DATA "Sub Group" Sheet, for sorting
var SubGroupObj = {}; // Object for "Subgroup" values
for (var SG = SubGroupAllValues.length - 1; SG >= 0; SG--) // for each row in the "Sub Group" sheet...
{
//... Add "Sub Group KEY (Col. #11 [K])" & "FYI Category Name (Col. #1 [A])" in Feed 2D Array.
SubGroupObj[SubGroupAllValues[SG][10]] = SubGroupAllValues[SG][0];
}
for (var F = FeedAllValues.length - 1; F >= 0; F--) // for each row in the "Feed" sheet...
{
var Feed_SubGroupKey = FeedAllValues[F][92]; // ...Add "Sub Group (Col. #93 [CO])" in array.
{
// If Sub Group array dont match "Sub Group Key (Col. #93 [CO])" & "FYI Topic Name (Col. #4 [D])... "
if (SubGroupObj[Feed_SubGroupKey] != FeedAllValues[F][3]) {
FeedAllValues[F][3] = SubGroupObj[Feed_SubGroupKey]; // ...Change FYI Category Name in FYI Topic Sheet
}
}
}
// Decalare var. from 2nd row to last row of FYI Topic sheet
var FeedDestinationRange = FeedDataSheet.getRange(2, 1, FeedAllValues.length, FeedAllValues[0].length);
FeedDestinationRange.setValues(FeedAllValues); // placed changed FYI Category 2D array in Mod sheet
var SubGroupAllRange = SubGroupDataSheet.getRange(2, 1, SubGroupDataSheet.getLastRow() - 1, SubGroupDataSheet.getLastColumn()); // complete range of Mod Status sheet
// Sort Sheet by - Category Name, then Category Topic
SubGroupAllRange.sort([{
column: 1,
ascending: true
}, {
column: 2,
ascending: true
}]);
Logger.log("The Sub Group Data Sheet has updated " + SubsDataLastRow - 1 + " data files")
}
Is there anyone who can assist me in adjusting this function to ignore any empty cells it encounters in the file?