Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript WorkSheet.getRange not working

bobsta666

New Coder
This is the code:
JavaScript:
function main(workbook: ExcelScript.Workbook) {
  // Access the data sheet
  let dataSheet = workbook.getWorksheet("Data");
  // Access the form sheet
  let formSheet = workbook.getWorksheet("TEF3202");
  // Access the range containing form fields
  let formRange = formSheet.getRange("A1:P107");
  // Determine the last row with data in column A of the data sheet
  let lastRowWithData = dataSheet.getUsedRange().getLastRow();
  // Access the range containing data in the last row
  let dataRange = dataSheet.getRange("A" + lastRowWithData + ":BE" + lastRowWithData);
 
  console.log(dataRange.getAddress())

  // Read data from the last row of the data sheet
  let data = dataRange.getValues();
  // Fill out the form fields
  formRange.getCell(6, 3).setValue(data[0][11]); // Example: Location
  formRange.getCell(6, 10).setValue(data[0][12]); // Example: ELR
  // Repeat this for all form fields as necessary
  // Iterate over the data
  data.forEach(row => {
    row.forEach(cell => {
      // Check if the cell is blank
      if (cell === "") {
        console.log("This cell is blank.");
      } else {
        console.log("Cell value:", cell);
      }
    });
  });
  // Save the changes
  // workbook.save();
}

The error is:
Code:
Line 15: Worksheet getRange: The argument is invalid or missing or has an incorrect format.

Can anybody help
 
So it's this line producing the error:
let dataRange = dataSheet.getRange("A" + lastRowWithData + ":BE" + lastRowWithData);

Does that string concatenation indeed evaluate to a valid range ?
 
Back
Top Bottom