0

do you have any clue on why the following code does not work?

begin=1    
Set FoundCell = ws.Range(Cells(begin,6),Cells(200000,6)).Find(What:=Content(i))

It says no Object found, if instead of Cells(begin,6),Cells(200000,6) I put "F:F" it does work. But I need to give dynamically the starting point of search (i.e. begin)

braX
  • 11,506
  • 5
  • 20
  • 33
Klapaucius
  • 57
  • 6

1 Answers1

2

If you do not define the "Parent" worksheet, then VBA assumes that the "Parent" worksheet is the ActiveSheet. Thus here:

ws.Range(Cells(begin,6),Cells(200000,6))

you have defined the "Parent" for .Range(), but for Cells it is not defined, thus it is considered to be the active one, which is obviously different than ws.

In general, make sure that you always define the worksheet that your Cells and Ranges should be located on. Like this:

With ws
    Set FoundCell = .Range(.Cells(begin,6),.Cells(200000,6)).Find(What:=Content(i))
End With
Vityata
  • 42,633
  • 8
  • 55
  • 100