Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Looop through many sheets


Hey all,

I have a workbook which contains many worksheets the first of which i
always called '01' and the
last which is always called 'Reference'. I also have a second workboo
called 'Test'.

What I need is a macro that scrolls through all the sheets in the firs
book and copies
the data from the last row to paste into a s sheet in Test so all thes
rows can be added together.

I have this (which doesn't work):

Sub NewQCM55()
Dim owksheet As Worksheet
For Each owksheet In Worksheet
Range("A8").Select
Selection.End(xlDown).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Windows("test.xls").Activate
Sheets("New_Jersey").Select
Range("B1").Select
ActiveSheet.Paste
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Windows("New_jersey_agent.xls").Activate
Next owksheet
End Sub



But my main issue is that I can't get the macro to move past the firs
sheet it is copying data from,
I know I can do this in a For loop but I would really aprieciate
pointer in the right direction.

Cheers

--
Hru4
-----------------------------------------------------------------------
Hru48's Profile: http://www.excelforum.com/member.php...fo&userid=2489
View this thread: http://www.excelforum.com/showthread.php?threadid=55400

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Looop through many sheets

first
For Each owksheet In Worksheet
For Each owksheet In WorksheetS

try something like this. UNtested.
You may be overwriting by copying the currentregion to one cell???

Sub NewQCM55()
Dim ws As Worksheet
For Each ws In Worksheets
ws.Range("a8").CurrentRegion.Copy
workbooks("test.xls").sheets("New_Jersey").Range(" B1")
workbooks("test.xls").sheets("New_Jersey").Rows(1) .Insert
Next ws
End Sub


--
Don Guillett
SalesAid Software

"Hru48" wrote in
message ...

Hey all,

I have a workbook which contains many worksheets the first of which is
always called '01' and the
last which is always called 'Reference'. I also have a second workbook
called 'Test'.

What I need is a macro that scrolls through all the sheets in the first
book and copies
the data from the last row to paste into a s sheet in Test so all these
rows can be added together.

I have this (which doesn't work):

Sub NewQCM55()
Dim owksheet As Worksheet
For Each owksheet In Worksheet
Range("A8").Select
Selection.End(xlDown).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Windows("test.xls").Activate
Sheets("New_Jersey").Select
Range("B1").Select
ActiveSheet.Paste
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Windows("New_jersey_agent.xls").Activate
Next owksheet
End Sub



But my main issue is that I can't get the macro to move past the first
sheet it is copying data from,
I know I can do this in a For loop but I would really aprieciate a
pointer in the right direction.

Cheers.


--
Hru48
------------------------------------------------------------------------
Hru48's Profile:
http://www.excelforum.com/member.php...o&userid=24895
View this thread: http://www.excelforum.com/showthread...hreadid=554007



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Looop through many sheets

It's grand as long as you enjoy making selections to slow down your code.

--
Don Guillett
SalesAid Software

"Hru48" wrote in
message ...

Thanks thats grand!


--
Hru48
------------------------------------------------------------------------
Hru48's Profile:
http://www.excelforum.com/member.php...o&userid=24895
View this thread: http://www.excelforum.com/showthread...hreadid=554007



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Looop through many sheets


Hi Hru48,

Try this, it should run faster b/c it's not made slower by screen
updating or making selections (as Don mentioned)...

Sub ModifiedSeeSheetNames()
Dim ws As Worksheet
Dim CopyRange As Range
Dim PasteRange As Range
Dim i As Long
Dim LastRow As Long

Set PasteRange =
Workbooks("test.xls").Sheets("New_Jersey").Range(" b1")
For Each ws In Workbooks("New_jersey_agent.xls").Worksheets '*
With ws
If .Name = "Summary" Or .Name = "Reference" Then GoTo ByPass
LastRow = .Cells(Rows.Count, "a").End(xlUp).Row
Set CopyRange = _
..Range(.Range("A" & LastRow), .Range("A" & LastRow).End(xlToRight))
If CopyRange.Columns.Count = .Columns.Count Then _
Set CopyRange = .Cells(CopyRange.Row, 1) '**
End With
CopyRange.Copy PasteRange.Offset(i, 0) '***
i = i + 1
ByPass:
Next ws
Set CopyRange = Nothing
Set PasteRange = Nothing

End Sub

Comments:
'*I have worded it like this to be precise in selection. However, if
the macro is to be used to copy more than one file change it to
something like: "For Each ws In ActiveWorkbook.Worksheets"
'**This is to prevent pasting errors if there is only data in column A
if this is the case the CopyRange becomes the whole row and a whole row
can't be pasted into column B of the other file.
Also, I'm just learning too & am not sure if the CopyRange needs to be
"Set" everytime or not (does anyone know?) - it works though so I
haven't changed it.
'***This assumes it doesn't matter what the order is when the rows are
added to the "test" file therefore new info is added to the bottom
rather than by inserting at the top (as in original macro).

Don,
just curious, why knock it when you could share some knowledge & offer
an alternative. Do you have any suggestions to improve my modified
version?

hth
Rob Brockett
NZ
Always learning & the best way to learn is to experience...


Don Guillett Wrote:
It's grand as long as you enjoy making selections to slow down your
code.

--
Don Guillett
SalesAid Software

"Hru48" wrote in
message ...

Thanks thats grand!


--
Hru48

------------------------------------------------------------------------
Hru48's Profile:
http://www.excelforum.com/member.php...o&userid=24895
View this thread:

http://www.excelforum.com/showthread...hreadid=554007



--
broro183
------------------------------------------------------------------------
broro183's Profile: http://www.excelforum.com/member.php...o&userid=30068
View this thread: http://www.excelforum.com/showthread...hreadid=554007

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
Multiple Sheets (Need to create 500 individual sheets in one workbook, pulling DATA Amaxwell Excel Worksheet Functions 4 August 17th 06 06:23 AM
How to repeat a code for selected sheets (or a contiguous range of sheets) in a Workbook? Dmitry Excel Worksheet Functions 6 March 29th 06 12:43 PM
How to repeat a code for selected sheets (or a contiguous range of sheets) in a Workbook? Dmitry Excel Programming 6 March 29th 06 12:43 PM
Macro for filter on protected workbook that works for all sheets, no matter what sheets are named? StargateFanFromWork[_3_] Excel Programming 6 January 26th 06 06:31 PM
Allocate Files to Sheets and Build a Master Sheet which Summarises All Sheets hanuman Excel Programming 0 September 9th 03 11:23 AM


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