Thanks Richard.
I really appreciate your assistance. The many and varied spellings for these "categories" was driving me up the wall. With this routine, Excel can search to find the "essential spelling" instead of the exact.
I have included the entire source. I invite your comments.
[vba] Function Find_Cat(wk1 As Worksheet, hunt As String) As Integer
'
' 04/16/09
'
' Find_Cat Given a data worksheet(wk1) and a
' category(hunt), Find_Cat searches the worksheet
' and returns the row number. If not found, the
' row number is zero.
'
' This code essentially allows many spelling
' variations to the categories.
'
' This was my idea, but I couldn't figure out how
' to get the data in a byte array. Richard Schollar
' of VBAX answered my query on how to do this.
'
'
http://www.vbaexpress.com/forum/showthread.php?t=19052
'
Dim str1 As String
Dim i As Long
Dim len_hunt As Integer
Dim len_text As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim m As Integer
Dim row As Integer
Dim found As Integer
Dim arr_h() As Byte
Dim arr_d() As Byte
len_hunt = Len(hunt)
arr_h = StrConv(hunt, vbFromUnicode)
For i = 1 To GetLastRowWithData(wk1)
len_text = Len(wk1.Cells(i, 1))
arr_d = StrConv(wk1.Cells(i, 1), vbFromUnicode)
l = 0
m = 0
found = 0
row = 0
For j = 0 To len_text - 1
If arr_h(l) = arr_d(m) Then
l = l + 1
found = found + 1
End If
m = m + 1
If found = len_hunt Then
row = i
Exit For
End If
Next j
If row <> 0 Then Exit For
Next i
Find_Cat = row
End Function [/vba]
Some notes: The text I'm searching for is in column "A" of the worksheet. The function returns the row number since I am actually searching for data on this row.
I thought this might be interesting to others since simple spelling/wording issues can cause many problems. This will not solve them all, but it does overcome a lot of spelling/wording problems. For example, assume I am looking for "Grounds and Maintenance Wages", and this is captured as "Grounds & Maintenance Wages". The compare will not work. If I condense this to "GRDSWAGE", and search the text for these characters in order, then I can find the data. My data is coming from several sources, and I have no control over these spellings.
GetLastRowWithData returns the number of rows on a worksheet. In my case, this number varies on just about every data sheet.