Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default Range in wrong book

Hi

I am using code to loop through all the files in a folder, read some data,
write back to the book containing the code and move on to the next book.

Part of my code has the following line:
m = Application.VLookup(Chr(ce.Column + 64), Range("month"), 2, 0)

Trouble is the named range is not in the book being read hence it doesn't
work. Is there an eaasier way other than copy the named range to every
workbook being read?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 196
Default Range in wrong book

Hi

Possibly you could store the address of the named range in a string
and then use that:

Dim strAddress as String
strAddress =
Split(Workbooks("YourBookWithTheNamedRange").Names ("month").RefersTo,"!")
(1)
m = Application.VLookup(Chr(ce.Column + 64), Range(strAddress), 2, 0)

Hope this helps!

Richard


On 8 Feb, 08:51, Newbie wrote:
Hi

I am using code to loop through all the files in a folder, read some data,
write back to the book containing the code and move on to the next book.

Part of my code has the following line:
m = Application.VLookup(Chr(ce.Column + 64), Range("month"), 2, 0)

Trouble is the named range is not in the book being read hence it doesn't
work. Is there an eaasier way other than copy the named range to every
workbook being read?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 968
Default Range in wrong book

You could use a Workbook.Range reference rather than the default
ActiveWorkbook.Range

m = Application.VLookup(Chr(ce.Column + 64), Workbooks("Workbook containing
range.xls").Range("month"), 2, 0)

Charles
______________________
Decision Models
FastExcel 2.3 now available
Name Manager 4.0 now available
www.DecisionModels.com

"Newbie" wrote in message
...
Hi

I am using code to loop through all the files in a folder, read some data,
write back to the book containing the code and move on to the next book.

Part of my code has the following line:
m = Application.VLookup(Chr(ce.Column + 64), Range("month"), 2, 0)

Trouble is the named range is not in the book being read hence it doesn't
work. Is there an eaasier way other than copy the named range to every
workbook being read?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default Range in wrong book

I was thinking on the same lines but...

m = Application.VLookup(Chr(ce.Column + 64),
Workbooks("Driver1.xls").Range("month"), 2, 0)

gives me a runtime error 438
object doesn't support property or methd



"Charles Williams" wrote:

You could use a Workbook.Range reference rather than the default
ActiveWorkbook.Range

m = Application.VLookup(Chr(ce.Column + 64), Workbooks("Workbook containing
range.xls").Range("month"), 2, 0)

Charles
______________________
Decision Models
FastExcel 2.3 now available
Name Manager 4.0 now available
www.DecisionModels.com

"Newbie" wrote in message
...
Hi

I am using code to loop through all the files in a folder, read some data,
write back to the book containing the code and move on to the next book.

Part of my code has the following line:
m = Application.VLookup(Chr(ce.Column + 64), Range("month"), 2, 0)

Trouble is the named range is not in the book being read hence it doesn't
work. Is there an eaasier way other than copy the named range to every
workbook being read?




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Range in wrong book


Dim rng as Range, rng1 as Range
set rng = Workbooks("Driver1.xls").Name("Month").ReferstoRan ge

m = Application.VLookup(Chr(ce.Column + 64), _
rng, 2, 0)

If you want to look in the same area in the activesheet instead of in
Driver1.xls then

Dim rng as Range
set rng = Workbooks("Driver1.xls").Name("Month").ReferstoRan ge
set rng1 = ActiveSheet.Range(rng.Address)
m = Application.VLookup(Chr(ce.Column + 64), _
rng1, 2, 0)


this assumes the named range Month is a singe contiguous block of cells.

--
Regards,
Tom Ogilvy


"Newbie" wrote:

I was thinking on the same lines but...

m = Application.VLookup(Chr(ce.Column + 64),
Workbooks("Driver1.xls").Range("month"), 2, 0)

gives me a runtime error 438
object doesn't support property or methd



"Charles Williams" wrote:

You could use a Workbook.Range reference rather than the default
ActiveWorkbook.Range

m = Application.VLookup(Chr(ce.Column + 64), Workbooks("Workbook containing
range.xls").Range("month"), 2, 0)

Charles
______________________
Decision Models
FastExcel 2.3 now available
Name Manager 4.0 now available
www.DecisionModels.com

"Newbie" wrote in message
...
Hi

I am using code to loop through all the files in a folder, read some data,
write back to the book containing the code and move on to the next book.

Part of my code has the following line:
m = Application.VLookup(Chr(ce.Column + 64), Range("month"), 2, 0)

Trouble is the named range is not in the book being read hence it doesn't
work. Is there an eaasier way other than copy the named range to every
workbook being read?






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default Range in wrong book

As usual Tom, you have come up with the goods.

I hope nice things happen to you.

Thanks.



"Tom Ogilvy" wrote:


Dim rng as Range, rng1 as Range
set rng = Workbooks("Driver1.xls").Name("Month").ReferstoRan ge

m = Application.VLookup(Chr(ce.Column + 64), _
rng, 2, 0)

If you want to look in the same area in the activesheet instead of in
Driver1.xls then

Dim rng as Range
set rng = Workbooks("Driver1.xls").Name("Month").ReferstoRan ge
set rng1 = ActiveSheet.Range(rng.Address)
m = Application.VLookup(Chr(ce.Column + 64), _
rng1, 2, 0)


this assumes the named range Month is a singe contiguous block of cells.

--
Regards,
Tom Ogilvy


"Newbie" wrote:

I was thinking on the same lines but...

m = Application.VLookup(Chr(ce.Column + 64),
Workbooks("Driver1.xls").Range("month"), 2, 0)

gives me a runtime error 438
object doesn't support property or methd



"Charles Williams" wrote:

You could use a Workbook.Range reference rather than the default
ActiveWorkbook.Range

m = Application.VLookup(Chr(ce.Column + 64), Workbooks("Workbook containing
range.xls").Range("month"), 2, 0)

Charles
______________________
Decision Models
FastExcel 2.3 now available
Name Manager 4.0 now available
www.DecisionModels.com

"Newbie" wrote in message
...
Hi

I am using code to loop through all the files in a folder, read some data,
write back to the book containing the code and move on to the next book.

Part of my code has the following line:
m = Application.VLookup(Chr(ce.Column + 64), Range("month"), 2, 0)

Trouble is the named range is not in the book being read hence it doesn't
work. Is there an eaasier way other than copy the named range to every
workbook being read?



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
VBA Range error - How does this work and what am I doing wrong? UIBC Excel Programming 6 October 15th 06 08:56 PM
Can I protect a range of worksheets in a book with one action? Sussex Fran Excel Worksheet Functions 2 June 10th 05 03:02 PM
User input as a range. What am I doing wrong? Irada Shamilova[_2_] Excel Programming 0 October 26th 04 08:34 AM
User input as a range. What am I doing wrong? Irada Shamilova Excel Programming 1 October 25th 04 04:23 PM
deleting wrong range! gavmer[_44_] Excel Programming 3 July 2nd 04 02:08 AM


All times are GMT +1. The time now is 10:22 AM.

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

About Us

"It's about Microsoft Excel"