Question

Is it possible to use .find method to look for data in a hidden workbook?

I have userform, which saves data to opened (but hidden) workbook. I want to make sure that when I enter invoive in one of textbox it was not inserted before.

I thought about using .find method but it gives me error 91 object variable or with block not set.

I checked those variable and they are set but I came up with an idea it may not go well with hidden workbook.

Below I pasted part of code. Error appears at If skoroszyt...

If Lastrow <> 1 And nr_faktury <> "" Then



    If skoroszyt.Worksheets(nazwa_arkusza).Range(faktury_range).Find(nr_faktury) = True Then
        MsgBox ("Podany nr faktury został podany w fakturze nr" & _
        skoroszyt.Worksheets(nazwa_arkusza).Range(faktury_range).Find(nr_faktury).Address & vbNewLine & _
        "Faktura nie została zapisana")
        Exit Sub
    End If

End If
Was it helpful?

Solution

I think you mean this one:

Dim rng As Range

If Lastrow <> 1 And nr_faktury <> "" Then
    Set rng = skoroszyt.Worksheets(nazwa_arkusza).Range(faktury_range).Find(What:=nr_faktury, _
                                                                            LookAt:=xlWhole, _
                                                                            LookIn:=xlValues, _
                                                                            MatchCase:=False)
    If Not rng Is Nothing Then
        MsgBox "Podany nr faktury zostal podany w fakturze nr" & _
            rng.Address & vbNewLine & "Faktura nie zostala zapisana"
        Exit Sub
    End If
End If

for partial match, change LookAt:=xlWhole to LookAt:=xlPart

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top