Using Excel 2003, I am trying to record a macro in file1 that will compare the values in a certain cell with the values in a cell in another workbook (file2). I want the user to be prompted to select the file to compare.
The following code will prompt for a file but then the subsequent formula generates a #REF error. I tested the syntax of the IF function by hardcoding the filename and it works fine so long as both files are saved to the same directory (code included but commented out). However, filenames will change - and the files are not guaranteed to be in the same directory, so this is not an option. I believe my issue is how i am referencing the 2nd workbook.
I even tried populating a different cell in file1 with the name of the file to compare with (again see code that is commented out) and that didn't help (nor do I really want to implement that approach).
I've looked in depth in the threads and FAQ's on this site and on Google, but I don't think I'm phrasing my question correctly.
The following code will prompt for a file but then the subsequent formula generates a #REF error. I tested the syntax of the IF function by hardcoding the filename and it works fine so long as both files are saved to the same directory (code included but commented out). However, filenames will change - and the files are not guaranteed to be in the same directory, so this is not an option. I believe my issue is how i am referencing the 2nd workbook.
I even tried populating a different cell in file1 with the name of the file to compare with (again see code that is commented out) and that didn't help (nor do I really want to implement that approach).
I've looked in depth in the threads and FAQ's on this site and on Google, but I don't think I'm phrasing my question correctly.
Code:
Sub CompareFiles4()
Dim TheCompareFile
Dim LastRow
'get the filename to compare with
'Sheets("Lookup List Values").Select
'Sheets("Lookup List Values").Activate
'With ActiveSheet
' Range("B10").Select
' TheCompareFile = Selection.Value
'End With
Sheets("Final").Select
'unprotect sheet
ActiveSheet.Unprotect
LastRow = Range("A" & ActiveSheet.Rows.Count).End(xlUp).Row
'insert formula to compare reports
Range("T4:T" & LastRow) = _
"=IF('[& TheCompareFile]summary'!RC[-18]="""",""DATA N/A"",IF(MID(RC[-19],1,7)<>MID('[& TheCompareFile]summary'!RC[-18],1,7),""Different Reviewer"",IF(RC[-6]='[& TheCompareFile]summary'!RC[-15],""OK"",'[& TheCompareFile]summary'!RC[-15])))"
'insert formula to compare SREA and QVR reports
' Range("T4:T" & LastRow) = _
' "=IF('[176551-b.xls]summary'!RC[-18]="""",""DATA N/A"",IF(MID(RC[-19],1,7)<>MID('[176551-b.xls]summary'!RC[-18],1,7),""Different Reviewer"",IF(RC[-6]='[176551-b.xls]summary'!RC[-15],""OK"",'[176551-b.xls]summary'!RC[-15])))"
ActiveWorkbook.Save
'reprotect sheet
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub