Excel spreadsheet duplicate values purger

Hello,
I’m fairly new to applescripting, but I have a basic understanding. I wrote the script below in an attempt to delete rows which have the same value applied to a cell as the row above it. Problem is, I keep getting an error “Microsoft Excel got an error: The object you are trying to access does not exist”. The value is found in the first cell, but when it checks the next cell something isn’t right. When I “get properties” of the cell in question, the values show up. Here’s the script:


tell application “Microsoft Excel”
set lastRow to ((count of rows of used range of active sheet) + 1)
set currRow to 1
set c to “B”
repeat until currRow = lastRow
set currSKU to string value of cell (c & currRow) of active sheet --as text
set nextSKU to string value of cell {c & currRow + 1} of active sheet --as text
if currSKU = nextSKU then
delete row (currRow)
end if
set currRow to (currRow + 1)
end repeat
end tell

When deleting rows, its best to work from the bottom up.

tell application "Microsoft Excel"
	set maxRow to count of rows of used range of active sheet
	repeat with currentRow from maxRow to 2 by -1
		
		set currVal to (value of row currentRow of column 2 of active sheet)
		
		set nextVal to (value of row (currentRow - 1) of column 2 of active sheet)
		
		if currVal = nextVal then
			delete range (row currentRow) of active sheet
		end if
	end repeat
end tell