+ Reply to Thread
Results 1 to 6 of 6

Shuffle through sheets in a loop?

  1. #1
    Registered User
    Join Date
    03-24-2006
    Posts
    38

    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?

  2. #2
    John
    Guest

    Re: 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" <erikhs.2b523q_1153221906.7632@excelforum-nospam.com> wrote in
    message news:erikhs.2b523q_1153221906.7632@excelforum-nospam.com...
    >
    > 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. #3
    Jason Zischke
    Guest

    RE: 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. #4
    Registered User
    Join Date
    03-24-2006
    Posts
    38
    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!

  5. #5
    Registered User
    Join Date
    03-24-2006
    Posts
    38
    Quote Originally Posted by Jason Zischke
    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?

  6. #6
    Ed
    Guest

    Re: 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" <erikhs.2b8pcq_1153392006.059@excelforum-nospam.com> wrote in
    message news:erikhs.2b8pcq_1153392006.059@excelforum-nospam.com...
    >
    > 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1