How to compare two Excel workbook's cell values
Hi,
We are trying to compare two Excel workbooks by specifying which cells should be compared as the column orders don't match in the files. We aren't a very technical team and tried to run the code below, but we get the following error (see screencapture attached too):
'TypeError: xfile1.Cells is not a function'
function CompareExcel()
{
let Excel = getActiveXObject("Excel.Application");
let xlfile1 = "S:\\Software\\mytilney.xlsx";
let xlfile2 = "S:\\Software\\plan.xlsx";
Excel.Workbooks.Open(xlfile1);
Excel.Workbooks.Open(xlfile2);
//let xsheet1 = xlfile1.Sheets("Sheet1");
//let xsheet2 = xlfile2.Sheets("Sheet1");
let RowCount = Excel.ActiveSheet.UsedRange.Rows.Count;
let ColumnCount = Excel.ActiveSheet.UsedRange.Columns.Count;
let Cells = Excel.ActiveSheet.UsedRange.Cells.Select;
for (let i = 1; i <= RowCount; i++) {
if (xlfile1.Cells(i,1).Value === xlfile2.Cells(i,1).Value) {
Log.Message("The files are the same.");
}};
Excel.Quit();
}
Is there anyone who could help is fix this this error please? Any help would be much appreciated.
We used the following documentation to produce this code:
Thanks,
Ivett