Can anyone explain to me why the following code only works when I manually type in the criteria onto an Excel spreadsheet. The data that does not work is information from an Access database. For some reason or another when I run the code on the Access database spreadsheet data I always get 0 for the count. If I open a new blank spreasheet and manually add some data it works fine
Option Compare Text
Public Sub FindHat()
Dim bn As Long
Dim rngLastHatEnd As Range
Dim hn As Long
Dim de As Long
Dim TheCount Long
'find the last instance of END HAT to minmize the search range
Set rngLastHatEnd = Columns("B:B").Find(What:="Hat End", After:=Range("B65536"), _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, _
MatchCase:=False, SearchFormat:=True)
If Not rngLastHatEnd Is Nothing Then
For bn = 1 To rngLastHatEnd.Row
If Cells(bn, 2).Text = "Hat" Then
For hn = bn To rngLastHatEnd.Row
If Cells(hn, 2).Text = "Hat End" Then
For de = bn To hn
If Cells(de, 2).Text = "Size" And Cells(de, 9).Value >= 0.1 Or Cells(de, 9).Value < 0.5 Then
TheCount = TheCount + 1
Exit For
End If
Next de
Exit For
End If
Next hn
End If
Next bn
End If
MsgBox "The Count is: " & TheCount, vbInformation + vbOKOnly
End Sub