Retrieve text from an htmltable

How do I convert an HTMLtable to read and recognise variable text in a row instead of the row number?

Bear with me, I have limited Robot experience and I am hacking away at an excerpt of someone elses script/function. I have attached the function, can someone please tell me what I need to amend for the HTMLTable action command to recognise the variable I have set as opposed to looking for the row number. See below for the script (It's a bit of a mess, so ignore anything irrelevant). I'm simply trying to get the HTMLtable action at the bottom to work so it will click on the desired row, but by recognising the text, not the row num. Cheers.

'_________________________________________________ _____________
'function: selectDept()
'parameters: deptName - Department Name in Department table to select
'description: read contents of department table
' check department name is present
' read each row to first instance of department name, click this row
'author: Mike
'modified: 18/03/2008 new
'_________________________________________________ _____________

Function selectDept(table As String, value as string) As String

Dim rc as Integer
Dim Result as integer
dim actualname as string

Window SetContext, "CurrentWindow",""

actualname=identifyObject("htmltable","Department Table")

dim rowNum as integer
dim tableText as string
dim currentRow as string
dim htmltablecell as string
'dim deptName as string
dim rowEnd as integer
dim rowDept as string
'dim textLen as integer
'dim targetRow as integer
'dim table as string

'read table text
Result=SQAGetProperty("Type=HTMLTable;HTMLId="&amp ;actualname,"innerText",tableText)
if Result= 0 then
SQAlogmessage sqapass, "TEST: check message: expected text (" &table &") displayed correctly",""
SQAlogmessage sqafail, "TEST: check message: expected text (" &table &") displayed correctly",""

End If


'check that deptName present in displayed table first
If Result = 0 then
SQALogMessage sqaWarning,"info: select department: department not in list - aborting",""
End If


Do While (Instr(1,tableText,Chr(13) &Chr(10),0)) >1

'LenB( value$)

'msgbox rowDept

If tableText=value then 'found required row
SQALogMessage sqapass,"found required row",""
'End If
Exit Do
End If

'find end of row at CR/LF pair
rowEnd=Instr(1,tableText,Chr(13) &Chr(10),0)
If rowEnd > 0 then
'discard current row
End If


'click on row in table

SQALogMessage sqaNone,"info: select department: selecting row ("&value &")",""

HTMLTable Click, "HTMLId="&actualname, "Text="&value &";Col=1"


End Function