Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #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!

  #2   Report Post  
Posted to microsoft.public.excel.misc
Ardus Petus
 
Posts: n/a
Default subscript out of range error in excell

Try:
Set mlUsed = Workbooks(nassisfile).Worksheets(2).Range("C:D")
in order to access to value of variable nassisfile

HTH
--
AP

"Lilivati" a écrit dans le message de news:
...
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!



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


Ardus Petus wrote:
Try:
Set mlUsed = Workbooks(nassisfile).Worksheets(2).Range("C:D")
in order to access to value of variable nassisfile

HTH
--
AP


I tried that, and it still gives me the same error. It is like it is
somehow not remembering the variable.

If I ask a message box to display the value of nassisfile, the first
time I try to change a cell it will display the name, and give me the
error. The next time I try it the message box is blank (it has lost
all touch with the variable nassisfile).

I tried replacing my first code with:

Public modelfile As String
Public nassislist As String

Public Sub Workbook_Open()
modelfile = ThisWorkbook.Name
nassisfile = "masterlist.xls"
End Sub


just as a way of bugtesting, since the value of nassisfile must
ultimately be defined by the user. The same error results.

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

Alright, ignore that previous message...I made a silly mistake with the
naming and the simplified version

Public Sub Workbook_Open()
modelfile = ThisWorkbook.Name
nassisfile = "masterlist.xls"
End Sub

works. However when I try to define nassisfile in the if loop I have
in the first post the worksheet change script is unable to find the
nassisfile variable.

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

The problem seems not to be in the if loop but in the
Application.GetOpenFilename procedure. It is simply not acknowledging
that this is defining nassisfile! It had no problems with this on
Friday, this is driving me nuts!


Lilivati wrote:
Alright, ignore that previous message...I made a silly mistake with the
naming and the simplified version

Public Sub Workbook_Open()
modelfile = ThisWorkbook.Name
nassisfile = "masterlist.xls"
End Sub

works. However when I try to define nassisfile in the if loop I have
in the first post the worksheet change script is unable to find the
nassisfile variable.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Range with unused formula messing up x axis on dynamic graph [email protected] Charts and Charting in Excel 2 February 2nd 06 08:02 PM
Help PLEASE! Not sure what answer is: Match? Index? Other? baz Excel Worksheet Functions 7 September 3rd 05 03:47 PM
Cannot Expand Named Range - when size of the Range exceeds Snig Excel Discussion (Misc queries) 1 July 7th 05 01:46 PM
How do I advance the range by one row Excell VBA automatically Eric Excel Discussion (Misc queries) 1 January 28th 05 06:11 PM
How do I advance the range by one row Excell VBA automatically Eric Excel Discussion (Misc queries) 0 January 28th 05 05:47 PM


All times are GMT +1. The time now is 12:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"