Exclude Hidden rows when working with Excel Data

Hi All,
I have a script that searches for the string “City Name” and then displays the name of the city from a Excel file .
The excel file will contain many rows containing the string “City Name” and the name of the city in the next column. Here is the code:

try
	tell application "Microsoft Excel"
		tell worksheet "Sheet1" of active workbook
			set worksheetCells to (value of used range)
			set totalRows to length of worksheetCells
		end tell
	end tell
on error
	error "The File is not open."
end try

repeat with i from 1 to totalRows
	if item i of worksheetCells contains "City Name" then
		set nameofCity to (item 2 of (item i of worksheetCells)) as text
                display dialog nameofCity
	end if
end repeat

This works fine. But sometimes the excel file contains hidden rows that contain the string “City Name”. I want to exclude the results of the hidden rows. How can I achieve this? I know I can delete the hidden rows :slight_smile:

This is done. Here is the solution:

tell application "Microsoft Excel"
	tell (get used range of active sheet of active workbook)
		
		repeat with i from 1 to count rows
			if hidden of row i of used range of active sheet then
				log "row " & i & " is hidden"
			else
				set v to value of row i as text
				if v contains "City Name" then
					set cell_name to "B" & i
					set name_of_city to (get value of cell cell_name) as text
				end if
			end if
		end repeat
		
	end tell
end tell