View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.misc
Lilivati
 
Posts: n/a
Default subscript out of range error in excell

I am trying to work with two workbooks, with workbook A looking up
information in workbook B. When workbook A opens it prompts the user
to open workbook b:

Public modelfile As String
Public nassisfile As String

'on open event for workbook A
Sub Workbook_Open()

modelfile = ThisWorkbook

If nassisfile = "" Then
MsgBox "Please open a NASSIS reference file."
nassisfile = Application.GetOpenFilename("Excel Files,*.xls", 1,
"Select a NASSIS file.")
Workbooks.Open nassisfile
Workbooks(modelfile).Activate
End If

End Sub


This part works perfectly. The reference file (workbook B) opens as
instructed and workbook A is reactivated.

Then in the worksheet change event for workbook A I have the following:

Sub Worksheet_Change(ByVal Target As Range)
Dim Val As Range
Dim cell As Range
Dim part As String
Dim desc As String
Dim mlUsed As Range
Dim msg As String

'here is where the error occurs
Set mlUsed = Workbooks("nassisfile").Worksheets(2).Range("C:D")


Set Val = Range("B:B")

For Each cell In Target
If Union(cell, Val).Address = Val.Address And cell.text < "" Then
part = cell.text
desc = WorksheetFunction.VLookup(part, mlUsed, 2, False)
cell.Offset(0, 2) = desc
End If
Next cell

End Sub

Now workbook B (nassisfile) definitely exists- the user just opened it!
Yet I am getting this error. This is very frustrating as this code
worked perfectly when I left it on Friday, and when I solved a
different problem today it no longer works. I eliminated all the
changes I made today and it still will not function. Please help!