Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Shuffle through sheets in a loop?


Hi,

I would like to copy an identical selection from multiple sheets
automatically, and then pasting to another sheet. How can i code a loop
that shuffles through the sheets without knowing their names, and then
stopping when it reaches the "paste" sheet? Is there some kind of
numerical sheet "category" that i can use?


--
erikhs
------------------------------------------------------------------------
erikhs's Profile: http://www.excelforum.com/member.php...o&userid=32788
View this thread: http://www.excelforum.com/showthread...hreadid=562405

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 205
Default Shuffle through sheets in a loop?

Erikhs,

Try this:

Sub SheetsLoop()

Dim wkb As Workbook
Dim wks As Worksheet
Dim i As Integer

Set wkb = Application.ActiveWorkbook
For i = 1 To wkb.Worksheets.Count
Set wks = wkb.Worksheets(i)
If wks.Name < "Paste" Then
'Add your copy paste code here
Else
'Do nothing or add other code here
End If
Next i

End Sub

The above code checks the sheet name so you'll need to change the "Paste"
name to whatever you're clling your target sheet.

Hope that helps

Best regards

John



"erikhs" wrote in
message ...

Hi,

I would like to copy an identical selection from multiple sheets
automatically, and then pasting to another sheet. How can i code a loop
that shuffles through the sheets without knowing their names, and then
stopping when it reaches the "paste" sheet? Is there some kind of
numerical sheet "category" that i can use?


--
erikhs
------------------------------------------------------------------------
erikhs's Profile:
http://www.excelforum.com/member.php...o&userid=32788
View this thread: http://www.excelforum.com/showthread...hreadid=562405



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 147
Default Shuffle through sheets in a loop?

Hi erikhs

Try This

ActiveWorkbook.Sheets(x)

"x" Refers to the Tabs at the bottom

e.g. :

If your looking for the third sheet along the bottom the "x" equals 3.

Jason Zischke


"erikhs" wrote:


Hi,

I would like to copy an identical selection from multiple sheets
automatically, and then pasting to another sheet. How can i code a loop
that shuffles through the sheets without knowing their names, and then
stopping when it reaches the "paste" sheet? Is there some kind of
numerical sheet "category" that i can use?


--
erikhs
------------------------------------------------------------------------
erikhs's Profile: http://www.excelforum.com/member.php...o&userid=32788
View this thread: http://www.excelforum.com/showthread...hreadid=562405


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Shuffle through sheets in a loop?


Hi, i cant get it to work, it seems it copies the data on the first
sheet over and over again, here is my code:

Sub Macro1()
'The data i want to copy
Dim MyRange As Range

'
Dim wkb As Workbook
Dim wks As Worksheet
Dim i As Integer

'Dynamic range for the separate sheets
Range("a6", Range("v6").End(xlDown)).Name = "MyRange"
On Error Resume Next

'Add title and "paste" sheet"
Rows("5").Copy
Worksheets.Add.Name = "Edited"

'Your code
Set wkb = Application.ActiveWorkbook
For i = 1 To wkb.Worksheets.Count
Set wks = wkb.Worksheets(i)
If wks.Name < "Redigeret" Then
'My copy/pasté
Range("MyRange").Copy
Sheets("Edited").Select
'Paste at first blank cell in column A. This doesn't work either by
'the way. Any suggestions?
Set firstBlank = Range("A1").End(xlDown).Offset(1, 0)
Range("firstblank").Select
ActiveCell.PasteSpecial
Else

End If
Next i

End Sub


What could be wronh? Anyone else? Help would really be appreciated!


--
erikhs
------------------------------------------------------------------------
erikhs's Profile: http://www.excelforum.com/member.php...o&userid=32788
View this thread: http://www.excelforum.com/showthread...hreadid=562405

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Shuffle through sheets in a loop?


Jason Zischke Wrote:
Hi erikhs

Try This

ActiveWorkbook.Sheets(x)

"x" Refers to the Tabs at the bottom

e.g. :

If your looking for the third sheet along the bottom the "x" equals 3.

Jason Zischke


[/color]

Thank you for your suggestion, but how can i incorporate this into a
loop?
Any ideas?


--
erikhs
------------------------------------------------------------------------
erikhs's Profile: http://www.excelforum.com/member.php...o&userid=32788
View this thread: http://www.excelforum.com/showthread...hreadid=562405



  #6   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default Shuffle through sheets in a loop?

Sub Foo_Test()

Dim x As Long
Dim wkb As Workbook
Dim wks As Worksheet

Set wkb = ActiveWorkbook
For x = 1 To wkb.Worksheets.Count
Set wks = wkb.Worksheets(x)
' Do something
Next x

End Sub

--
Ed
Chief Chef,
Kludge Code Cafe
"Spaghetti Is Our Specialty!"
'
"erikhs" wrote in
message ...

Jason Zischke Wrote:
Hi erikhs

Try This

ActiveWorkbook.Sheets(x)

"x" Refers to the Tabs at the bottom

e.g. :

If your looking for the third sheet along the bottom the "x" equals 3.

Jason Zischke




Thank you for your suggestion, but how can i incorporate this into a
loop?
Any ideas?


--
erikhs
------------------------------------------------------------------------
erikhs's Profile:
http://www.excelforum.com/member.php...o&userid=32788
View this thread: http://www.excelforum.com/showthread...hreadid=562405
[/color]


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
Loop in sheets al007 Excel Programming 4 November 28th 05 03:07 PM
Loop through all sheets in workbook jennie Excel Programming 7 October 26th 05 11:54 AM
Loop through sheets michael Excel Programming 2 September 8th 04 02:52 PM
excel VBA - for loop for several sheets paku Excel Programming 2 April 11th 04 12:33 AM
Loop across Sheets and number of sheets Raj[_8_] Excel Programming 2 December 18th 03 09:18 AM


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