Same sub different results

  • Thread starter Thread starter DredanZyl
  • Start date Start date
D

DredanZyl

Can anyone tell me why the very same sub gives different results whe
run from the Personal.xls workbook? Here is the code:

Sub VLookUpRange()
Dim rName As Name
Set rName = ThisWorkbook.Names("WhatEver")
End Sub

This sub works fine with all workbooks except Personal.xls.

I get the 'Run time error 1004 - application defined or object-define
error' when I try to run it from Personal.xl
 
Hi DredanZyl

Do you have a defined name called "Whatever" in "Personal.xls" since your
code refers to that name in "ThisWorkbook" which is the workbook executing
the sub. Do you mean "ActiveWorkbook".

--
XL2002
Regards

William

(e-mail address removed)

| Can anyone tell me why the very same sub gives different results when
| run from the Personal.xls workbook? Here is the code:
|
| Sub VLookUpRange()
| Dim rName As Name
| Set rName = ThisWorkbook.Names("WhatEver")
| End Sub
|
| This sub works fine with all workbooks except Personal.xls.
|
| I get the 'Run time error 1004 - application defined or object-defined
| error' when I try to run it from Personal.xls
|
|
| ---
| Message posted
|
 
Perhaps Personal.xls doesn't have a name called 'WhatEver'. This is where
you need error checking, like so

On Error Resum Next
Set rName = ThisWorkbook.Names("WhatEver")
If rName Is Nothing Then
MsgBox "Ooops!"
End If

It is probable that you don't mean ThisWorkbook which is the workbook the
code is in, buty ACtiveWorkbook, which is the one you are working on.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Thanks William, that was it. I should have put 'Active workbook'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top