I've refined my code, but l found that using the "workbook open" technique - it takes extremely long to go through all of my 424 observations. I ended the run after 15 minutes because I'm assuming there must be another alternative. I hope!
Below i've included the sub procedures that I initially posted and the revised code based on the suggestions posted by ciello
Option 1 uses a vlookup formula and runs relatively fast. But it still truncates explanations that contain more than 255 characters.
Option 2 uses the workbook open method.
Sub Option1()
Dim MyCount
MyCount = Range(Range("A5"), Range("A5").End(xlDown)).count + 4
For i = 5 To MyCount
Cells(i, 15).Formula = "=VLOOKUP(C" & i & ",'C:\My Documents\Survey\[" & Cells(i, 1) & _
".xls]Explanations'!$A$1:$B$100,2,FALSE)"
Next i
End Sub
Sub Option2()
Application.ScreenUpdating = False
Dim c As Range
Dim StrToFind As String
Dim MyCount
MyCount = Range(Range("A5"), Range("A5").End(xlDown)).count + 4
'On Error GoTo ErrorOccurred
For i = 5 To MyCount
ThisWorkbook.Activate
Sheets(1).Activate
StrToFind = Cells(i, "C")
Workbooks.Open Filename:= _
"C:\My Documents\Survey\" & Cells(i, 1) & ".xls"
Sheets("Explanations").Select
Set c = Range("A1:A100").Find(What:=StrToFind, After:=Range("A1"), LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
If Not c Is Nothing Then
ThisWorkbook.ActiveSheet.Cells(i, 15) = c.Offset(0, 1)
Else
ThisWorkbook.ActiveSheet.Cells(i, 15) = "Not found"
End If
ActiveWorkbook.Close (False)
Next i
Exit Sub
ErrorOccurred:
ThisWorkbook.ActiveSheet.Cells(i, 15) = "ERROR"
Resume Next
Application.ScreenUpdating = False
End Sub
Does anyone have any other suggestions? I attempted to search for help on MS's website:
http://support.microsoft.com/?scid=.../servicedesks/bin/kbsearch.asp?article=213841
it has sample code - but it's foreign to me
Also, I noticed that when I ran the "option 2" macro - an error occured for 1 observation - but I'm not sure why it happend exactly. There were 1,104 characters in that observation. But when I reduced the characters in that worksheet (to 25) and reran the macro - no error occured. Is there a certain range above 255 characters where an error arises?