Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default number of workbooks less 1

I have opened a number of workbooks, "wk01" through "wkXX". I have opened
another workbook, "info" , to collect information from "wk01" to "wkXX", copy
the information, paste to workbook "info" one at a time, and close each of
the "wkXX's" after the information is collected.

I must perform the procedure a number of times based on the number of
workbooks open less (subtract) 1. My workbook "info" where the informaton is
collected is closed when the routine is complete. The workbook "info" is the
last to close.

The following code does not work for me.

How can I perform the loop based on the number of workbooks open less 1?

Sub test()
Number = Workbooks.Count - 1
ActiveWindow.ActivateNext
For Count = 1 To Number
Range("b1:b5").Copy
Workbooks("info.xls").Activate
Range("a1").Select
ActiveCell.End(xlDown).Offset(1, 0).Select
ActiveCell.PasteSpecial xlPasteValues
ActiveWindow.ActivateNext
ActiveWindow.Close savechanges:=False
Next Count
End Sub

l-hawk
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default number of workbooks less 1


Untested but should be close to what you want...
'--
Sub test()
Dim lngCount As Long
Dim Number As Long
Number = Workbooks.Count
For lngCount = 1 To Number
If Not Workbooks(lngCount).Name = "info" Then
Workbooks(lngCount).Range("b1:b5").Copy
Workbooks("info.xls").Range("a1").End(xlDown).Offs et(1, 0).PasteSpecial xlPasteValues
Workbooks(lngCount).Close savechanges:=False
End If
Next lngCount
Workbooks("info.xls").Close savechanges:=True
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


(Excel Add-ins / Excel Programming)
"hawki"
wrote in message
I have opened a number of workbooks, "wk01" through "wkXX". I have opened
another workbook, "info" , to collect information from "wk01" to "wkXX", copy
the information, paste to workbook "info" one at a time, and close each of
the "wkXX's" after the information is collected.
I must perform the procedure a number of times based on the number of
workbooks open less (subtract) 1. My workbook "info" where the informaton is
collected is closed when the routine is complete. The workbook "info" is the
last to close.
The following code does not work for me.
How can I perform the loop based on the number of workbooks open less 1?

Sub test()
Number = Workbooks.Count - 1
ActiveWindow.ActivateNext
For Count = 1 To Number
Range("b1:b5").Copy
Workbooks("info.xls").Activate
Range("a1").Select
ActiveCell.End(xlDown).Offset(1, 0).Select
ActiveCell.PasteSpecial xlPasteValues
ActiveWindow.ActivateNext
ActiveWindow.Close savechanges:=False
Next Count
End Sub

l-hawk
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default number of workbooks less 1

The procedure stops at the line below.

Workbooks(lngCount).Range("b1:b5").Copy
--
l-hawk


"Jim Cone" wrote:


Untested but should be close to what you want...
'--
Sub test()
Dim lngCount As Long
Dim Number As Long
Number = Workbooks.Count
For lngCount = 1 To Number
If Not Workbooks(lngCount).Name = "info" Then
Workbooks(lngCount).Range("b1:b5").Copy
Workbooks("info.xls").Range("a1").End(xlDown).Offs et(1, 0).PasteSpecial xlPasteValues
Workbooks(lngCount).Close savechanges:=False
End If
Next lngCount
Workbooks("info.xls").Close savechanges:=True
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


(Excel Add-ins / Excel Programming)
"hawki"
wrote in message
I have opened a number of workbooks, "wk01" through "wkXX". I have opened
another workbook, "info" , to collect information from "wk01" to "wkXX", copy
the information, paste to workbook "info" one at a time, and close each of
the "wkXX's" after the information is collected.
I must perform the procedure a number of times based on the number of
workbooks open less (subtract) 1. My workbook "info" where the informaton is
collected is closed when the routine is complete. The workbook "info" is the
last to close.
The following code does not work for me.
How can I perform the loop based on the number of workbooks open less 1?

Sub test()
Number = Workbooks.Count - 1
ActiveWindow.ActivateNext
For Count = 1 To Number
Range("b1:b5").Copy
Workbooks("info.xls").Activate
Range("a1").Select
ActiveCell.End(xlDown).Offset(1, 0).Select
ActiveCell.PasteSpecial xlPasteValues
ActiveWindow.ActivateNext
ActiveWindow.Close savechanges:=False
Next Count
End Sub

l-hawk

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default number of workbooks less 1


It needs a sheet specified...
Workbooks(lngCount).Worksheets(1).Range("b1:b5").C opy

Same for...
Workbooks("info.xls").Worksheets(1).Range("a1").En d(xlDown).Offset(1, 0).PasteSpecial

Also...
Workbooks("info.xls") should probably be Workbooks("info") ?
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"hawki"
wrote in message
The procedure stops at the line below.
Workbooks(lngCount).Range("b1:b5").Copy
--
l-hawk


"Jim Cone" wrote:
Untested but should be close to what you want...
'--
Sub test()
Dim lngCount As Long
Dim Number As Long
Number = Workbooks.Count
For lngCount = 1 To Number
If Not Workbooks(lngCount).Name = "info" Then
Workbooks(lngCount).Range("b1:b5").Copy
Workbooks("info.xls").Range("a1").End(xlDown).Offs et(1, 0).PasteSpecial xlPasteValues
Workbooks(lngCount).Close savechanges:=False
End If
Next lngCount
Workbooks("info.xls").Close savechanges:=True
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


(Excel Add-ins / Excel Programming)
"hawki"
wrote in message
I have opened a number of workbooks, "wk01" through "wkXX". I have opened
another workbook, "info" , to collect information from "wk01" to "wkXX", copy
the information, paste to workbook "info" one at a time, and close each of
the "wkXX's" after the information is collected.
I must perform the procedure a number of times based on the number of
workbooks open less (subtract) 1. My workbook "info" where the informaton is
collected is closed when the routine is complete. The workbook "info" is the
last to close.
The following code does not work for me.
How can I perform the loop based on the number of workbooks open less 1?

Sub test()
Number = Workbooks.Count - 1
ActiveWindow.ActivateNext
For Count = 1 To Number
Range("b1:b5").Copy
Workbooks("info.xls").Activate
Range("a1").Select
ActiveCell.End(xlDown).Offset(1, 0).Select
ActiveCell.PasteSpecial xlPasteValues
ActiveWindow.ActivateNext
ActiveWindow.Close savechanges:=False
Next Count
End Sub

l-hawk

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default number of workbooks less 1


Please omit that last part about changing the workbook name...
--
Jim Cone


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default number of workbooks less 1

The procedure stops at the following line.

Workbooks("info.xls").Worksheets(info).Range("a1") .End(xlDown).Offset(1,
0).PasteSpecial xlPasteValues
--
l-hawk


"Jim Cone" wrote:


It needs a sheet specified...
Workbooks(lngCount).Worksheets(1).Range("b1:b5").C opy

Same for...
Workbooks("info.xls").Worksheets(1).Range("a1").En d(xlDown).Offset(1, 0).PasteSpecial

Also...
Workbooks("info.xls") should probably be Workbooks("info") ?
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default number of workbooks less 1


And what is the error you get?
Jim Cone

"hawki"
wrote in message
The procedure stops at the following line.

Workbooks("info.xls").Worksheets(info).Range("a1") .End(xlDown).Offset(1,
0).PasteSpecial xlPasteValues
--
l-hawk



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default number of workbooks less 1

I get the following error. Run time error "9". Subscript out of range.
--
l-hawk


"Jim Cone" wrote:


And what is the error you get?
Jim Cone

"hawki"
wrote in message
The procedure stops at the following line.

Workbooks("info.xls").Worksheets(info).Range("a1") .End(xlDown).Offset(1,
0).PasteSpecial xlPasteValues
--
l-hawk




  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default number of workbooks less 1


If you do not use an index number to identify a specific workbook or
worksheet then you must use the name of the workbook or worksheet.
All names are strings except for those referring to range objects,
so enclose info in quotation marks...
Worksheets("info")
'--
Jim Cone


"hawki"
wrote in message
I get the following error. Run time error "9". Subscript out of range.
--
l-hawk


"Jim Cone" wrote:
And what is the error you get?
Jim Cone



"hawki"
wrote in message
The procedure stops at the following line.

Workbooks("info.xls").Worksheets(info).Range("a1") .End(xlDown).Offset(1,
0).PasteSpecial xlPasteValues
--
l-hawk

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default number of workbooks less 1

Followng is the complete code which stops at the line below with an error
code of "9" subscript out of range.

Workbooks("info").Worksheets("info").Range("a1").E nd(xlDown).Offset(1,
0).PasteSpecial xlPasteValues


Sub test2()
Dim lngCount As Long
Dim Number As Long
Number = Workbooks.Count
For lngCount = 1 To Number
If Not Workbooks(lngCount).Name = "info" Then
Workbooks(lngCount).Worksheets(1).Range("b1:b5").C opy
Workbooks("info").Worksheets("info").Range("a1").E nd(xlDown).Offset(1,
0).PasteSpecial xlPasteValues
Workbooks(lngCount).Close savechanges:=False
End If
Next lngCount
Workbooks("info.xls").Close savechanges:=True
End Sub

--
l-hawk


"Jim Cone" wrote:


If you do not use an index number to identify a specific workbook or
worksheet then you must use the name of the workbook or worksheet.
All names are strings except for those referring to range objects,
so enclose info in quotation marks...
Worksheets("info")
'--
Jim Cone


"hawki"
wrote in message
I get the following error. Run time error "9". Subscript out of range.
--
l-hawk


"Jim Cone" wrote:
And what is the error you get?
Jim Cone



"hawki"
wrote in message
The procedure stops at the following line.

Workbooks("info.xls").Worksheets(info).Range("a1") .End(xlDown).Offset(1,
0).PasteSpecial xlPasteValues
--
l-hawk




  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default number of workbooks less 1


The error message indicates that a name is not correct.
I suspect the Workbooks("info") should be Workbooks("info.xls")

Also, If Not Workbooks(lngCount).Name = "info" should be
If Not Workbooks(lngCount).Name = "info.xls"

The worksheet name should be what is shown on the sheet tab.

Good luck with it - I have a project that just came in that I have to complete.

Jim Cone



"hawki"
wrote in message
Followng is the complete code which stops at the line below with an error
code of "9" subscript out of range.

Workbooks("info").Worksheets("info").Range("a1").E nd(xlDown).Offset(1,
0).PasteSpecial xlPasteValues


Sub test2()
Dim lngCount As Long
Dim Number As Long
Number = Workbooks.Count
For lngCount = 1 To Number
If Not Workbooks(lngCount).Name = "info" Then
Workbooks(lngCount).Worksheets(1).Range("b1:b5").C opy
Workbooks("info").Worksheets("info").Range("a1").E nd(xlDown).Offset(1,
0).PasteSpecial xlPasteValues
Workbooks(lngCount).Close savechanges:=False
End If
Next lngCount
Workbooks("info.xls").Close savechanges:=True
End Sub

--
l-hawk


"Jim Cone" wrote:


If you do not use an index number to identify a specific workbook or
worksheet then you must use the name of the workbook or worksheet.
All names are strings except for those referring to range objects,
so enclose info in quotation marks...
Worksheets("info")
'--
Jim Cone


"hawki"
wrote in message
I get the following error. Run time error "9". Subscript out of range.
--
l-hawk


"Jim Cone" wrote:
And what is the error you get?
Jim Cone



"hawki"
wrote in message
The procedure stops at the following line.

Workbooks("info.xls").Worksheets(info).Range("a1") .End(xlDown).Offset(1,
0).PasteSpecial xlPasteValues
--
l-hawk


  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default number of workbooks less 1

Thanks so much for your assitance. You have been a jewel.
--
l-hawk


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
How to tell the number of current open workbooks... [email protected] Excel Worksheet Functions 1 April 16th 07 04:06 PM
Totals across increasing number of Workbooks dd Excel Programming 0 January 15th 07 10:06 AM
Different Number of Workbooks each week Wally Steadman Excel Worksheet Functions 2 July 12th 06 01:27 PM
count number of workbooks open Ronaldo Excel Programming 2 April 21st 05 01:00 PM
Number of workbooks open Tim U[_2_] Excel Programming 1 June 30th 04 06:03 PM


All times are GMT +1. The time now is 02:51 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"