paco_santigo

09-03-2010, 09:21 PM

So I have a spreadsheet here: GoogleDocs (https://spreadsheets.google.com/ccc?key=0AlJPTZ4v7oYidHNLbmExdmU3RnZwNFdJUWQtT3pqQ3c&hl=en&authkey=CNq_hPcE)

The code I have is :

function addition() {

// Declare Variables

var inputCell, outputCell, tempValueHolder;

var ss = SpreadsheetApp.getActiveSpreadsheet();

var sheet = ss.getSheets()[0];

// Declare the range of the input numbers: Column C

var inputRange = sheet.getRange("C4:C41");

// Declare the Range of where you want the output numbers: Column D

var outputRange = inputRange.offset(0, 1);

// Calculate the column and row count. columns = 1, rows = 37

var colNum = inputRange.getNumColumns()-1;

var rowNum = inputRange.getNumRows()-1;

// Run the for loop

// There is only one column of data, C

for (var i=0; i<=colNum; i++);

{

// There are 37 rows of data, 4 through 41

for (var j=0; j<=rowNum; j++);

{

// Declare column and row info for cells

inputCell = inputRange.getCell(j,i); //from Column C

outputCell = outputRange.getCell(j,i); // to Column D

// Copy whatever is in Column D

tempValueHolder = outputCell.getValue();

// Set Column D's cell to be whatever is in Column C PLUS what WAS in Column D

// It's just adding Column C's value to Column D's

outputCell.setValue(inputCell.getValue()+tempValueHolder);

// Clear Column C

inputCell.clearContent();

// next row (supposedly)

}

}

}

What I'm trying to do is take Values entered in the C column and add them to the existing number in column D of the same row. I do this from the starting cell: C4 down the rows to C41. Again, taking the value in C4 and adding it to D4... or C4+D4=newD4, all the way down to row 41.

So here's the problem. Whenever I run the function it only completes the last line in the loop, as in the last row (41). If I change the range from C4:C41 to C4:C#, it always only completes the loop with the # row. I can't figure out why. I have spent 6 hours JUST on this problem. Please someone with more knowledge help me. Thank you.

The code I have is :

function addition() {

// Declare Variables

var inputCell, outputCell, tempValueHolder;

var ss = SpreadsheetApp.getActiveSpreadsheet();

var sheet = ss.getSheets()[0];

// Declare the range of the input numbers: Column C

var inputRange = sheet.getRange("C4:C41");

// Declare the Range of where you want the output numbers: Column D

var outputRange = inputRange.offset(0, 1);

// Calculate the column and row count. columns = 1, rows = 37

var colNum = inputRange.getNumColumns()-1;

var rowNum = inputRange.getNumRows()-1;

// Run the for loop

// There is only one column of data, C

for (var i=0; i<=colNum; i++);

{

// There are 37 rows of data, 4 through 41

for (var j=0; j<=rowNum; j++);

{

// Declare column and row info for cells

inputCell = inputRange.getCell(j,i); //from Column C

outputCell = outputRange.getCell(j,i); // to Column D

// Copy whatever is in Column D

tempValueHolder = outputCell.getValue();

// Set Column D's cell to be whatever is in Column C PLUS what WAS in Column D

// It's just adding Column C's value to Column D's

outputCell.setValue(inputCell.getValue()+tempValueHolder);

// Clear Column C

inputCell.clearContent();

// next row (supposedly)

}

}

}

What I'm trying to do is take Values entered in the C column and add them to the existing number in column D of the same row. I do this from the starting cell: C4 down the rows to C41. Again, taking the value in C4 and adding it to D4... or C4+D4=newD4, all the way down to row 41.

So here's the problem. Whenever I run the function it only completes the last line in the loop, as in the last row (41). If I change the range from C4:C41 to C4:C#, it always only completes the loop with the # row. I can't figure out why. I have spent 6 hours JUST on this problem. Please someone with more knowledge help me. Thank you.