I guys i'm new here. Got some experience with vb6/vb.net and this is more or less the first time i've tried doing something with Excel macros.
The thing is that i get an odd error when conducting a search in a excel sheet. an object(that by all means shouldn't be NULL/nothing) is NULL/nothing, and i cannot seem to find the error. however i belive it got something to do with macro memory somehow, since the problem rises after i've been using the macro for a while.
The debug points @
whole sub further down.
Dumping the code. just tell me if you're intrested of some of the data aswell.
I don't think you'll need more than that since you should be able to understand it anyhow.
many thanks in advance.
The thing is that i get an odd error when conducting a search in a excel sheet. an object(that by all means shouldn't be NULL/nothing) is NULL/nothing, and i cannot seem to find the error. however i belive it got something to do with macro memory somehow, since the problem rises after i've been using the macro for a while.
The debug points @
Code:
> Set rngFind = .FIND(TARGET)
//rngFind = Nothing and this should not happen.
//Unless the search cannot find a match to the keyword
> If Not rngFind Is Nothing Then //rngFind = Nothing
Dumping the code. just tell me if you're intrested of some of the data aswell.
Microsoft 2k3 pro edition
Using Excel 2k3 (11.8320.8221) SP3
//
Blad1=sheet1
Blad2=sheet2
Blad3=sheet3
\\
Code:
Public Sub findus(ByVal TARGET As String)
ListBox1.Clear
alist.Clear
Dim wbkthis As Workbook
Dim shtthis As Worksheet
Dim rngThis As Range
Dim rngFind As Range
Dim firstAddress As String
Dim addSelection As String
On Error GoTo errh
Set wbkthis = ThisWorkbook
Set shtthis = wbkthis.Worksheets(3)
Set rngThis = shtthis.Range("B2", "B" & Blad3.Cells(1, 1))
With rngThis
Set rngFind = .FIND(TARGET)
If Not rngFind Is Nothing Then
firstAddress = rngFind.Address
Do
Set rngFind = .FindNext(rngFind)
alist.AddItem (rngFind.Address)
ListBox1.AddItem (rngFind.Value)
Loop While Not rngFind Is Nothing And rngFind.Address <> firstAddress
End If
End With
Set rngThis = Nothing
Set shtthis = Nothing
Set wbkthis = Nothing
Set rngFind = Nothing
Exit Sub
errh:
Debug.Print Err.Description
Call MsgBox(Err.Description)
Exit Sub
End Sub
many thanks in advance.