View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
xlcharlie xlcharlie is offline
external usenet poster
 
Posts: 37
Default Run-time error '9' on With statement

I wrote some code to sort through a huge dataset in one workbook, find a
particular piece of data and insert it into another workbook. The code is
contained in a module in the latter workbook. The code worked fine, but I
tried to adapt it to do something similar in another module and started
getting a run time error. So I tried executing the original code and I'm
getting the same error now with the original code. How could the code have
worked and now it doesn't if I didn't change anything? The line(s) of code in
question is:

With Workbooks("Workbook_Name").Sheets("Sheet_Name").Ra nge"Named_Range")
'<<THIS LINE IS WHERE I GET THE ERROR
Set rngVariable = .Find(what:=strVariable, LookIn:=xlValues)
End With

If I activate the workbook I'm looking in I think it will fix this problem,
but I wanted to avoid this because it will cause the code to switch back and
forth between workboks again and again (the code is imbedded in a loop). Any
insight into the cause/solution would be much appreciated!

Thanks in advance.