Reputation: 1
I have created a named ranged called MW_DATA in my sheet which covers the range U12:AA105
Based on the data present there could be a variable number of rows of data in U12:AA105 every time I copy the data to a Games_Log sheet and clear the data in the cells.
I need to improve the code so the filteredData variable is a dynamic range of rows each time (e.g. it could be U12:AA12 or U12:AA75)
current code:
function SaveMWData() {
var dataSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Games_Log");
var dataRange = dataSheet.getDataRange();
var dataLocation = dataRange.getLastRow();
var mwData = sheet.getRange("MW_DATA");
mwData.copyTo(dataSheet.getRange(dataLocation + 1,1),{contentsOnly:true});
}
Above code keeps copying all rows, including blank rows into the Games_Log sheet
Code I can't figure out:
function SaveMWData() {
var unfilteredData = sheet.getRange("MW_DATA");
var filteredData = ??
filteredData.copyTo(dataSheet.getRange(dataLocation + 1,1),{contentsOnly:true});
}
Filtered data would only copy over the rows with data
Upvotes: 0
Views: 55
Reputation: 1
I believe I got it working as follow:
function SaveMWData() {
var dataSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Games_Log");
var dataRange = dataSheet.getDataRange();
var dataLocation = dataRange.getLastRow();
var row = sheet.getRange("MW_ROW").getValue();
var column = sheet.getRange("MW_COLUMN").getValue();
var numrows = sheet.getRange("MW_NUMROWS").getValue();
var numcolumns = sheet.getRange("MW_NUMCOLUMNS").getValue();
var mwData = sheet.getRange(row,column,numrows,numcolumns);
mwData.copyTo(dataSheet.getRange(dataLocation + 1,1),{contentsOnly:true});
}
Upvotes: 0