My goal is to copy and paste contact information from sheet 'callLog' to another sheet based on if a contact is "Bidding". In order to determine where to paste the information, I am collecting data from the first row of sheet 'meh' and putting it into an array. Vars rowGet and rowValues are collecting the correct information, but rowValues.length = 0. This is causing the following for loop to end early, and every value is pasted on top of each other.
Please help me understand why the array length is 0, and how to get the correct value.
Thanks, -Chris
Paste Location Table Setup:
+---+-----------+-----------+-----------+
| | A | B | x |
+---+-----------+-----------+-----------+
| 1 | Comp Name | ... | Comp Name |
+---+-----------+-----------+-----------+
| 2 | Cont Name | ... | Cont Name |
+---+-----------+-----------+-----------+
| 3 | Number | ... | Number |
+---+-----------+-----------+-----------+
| 4 | email | ... | email |
+---+-----------+-----------+-----------+
Code:
function distributeBidder() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName('Call Log');
sheet.activate();
var range = spreadsheet.getRangeByName("bidList");
var copySheet = spreadsheet.getSheetByName('This Works');
// find the ones whose value is "BIDDING", and add them to a list of cells we need to hide
var vBidders = [];
for (var r = 1; r <= range.getNumRows(); r++) {
for (var c = 1; c <= range.getNumColumns(); c++) {
var cell = range.getCell(r, c);
if (cell.getValue() == "BIDDING") {
vBidders.push(cell);
}
}
}
copySheet.activate();
// Iterate through confirmed bidders and collect the correct data to paste
for(var i = 0;i<vBidders.length;i++){
var cCell = vBidders[i];
var compName = cCell.offset(0, +1);
var contName = cCell.offset(0, +2);
var contNum = cCell.offset(0, +3);
var contMail = cCell.offset(0, +5);
//THIS SCRIPT DOES NOT WORK WITH HORIZONTALLY FORMATTED DATA
var rowGet = copySheet.getRange("A1:H1");
var rowValues = rowGet.getValues();
//rowValues.length is coming up with a value of 0 breaking everything
for (var j = 0 ; j < rowValues.length ; j++) {
if(rowValues[j] == "Company Name") {
var rowValNow = j+1;
compName.copyValuesToRange(copySheet, rowValNow, rowValNow, 1, 1);
contName.copyValuesToRange(copySheet, rowValNow, rowValNow, 2, 2);
contNum.copyValuesToRange(copySheet, rowValNow, rowValNow, 3, 3);
contMail.copyValuesToRange(copySheet, rowValNow, rowValNow, 4, 4);
break;
};
};
};
};
Link to view the spreadsheet in progress: https://docs.google.com/spreadsheets/d/1AmdmQuw7OLH7v2LV-XQ_xW3hSPAHzi289Zt65bx53W8/edit?usp=sharing