+ Reply to Thread
Results 1 to 7 of 7

Loop for all Worksheets

Hybrid View

RAparente Loop for all Worksheets 12-08-2008, 11:25 AM
Bob Phillips Is this what you want? ... 12-08-2008, 11:35 AM
RAparente HI. my working file is the... 12-08-2008, 11:44 AM
royUK Is this whay ytou mean, place... 12-08-2008, 11:55 AM
RAparente Hi. The Macro5 codes only... 12-09-2008, 03:09 AM
royUK Your post does not comply... 12-08-2008, 11:40 AM
royUK Then you either need to amend... 12-09-2008, 07:39 AM
  1. #1
    Registered User
    Join Date
    11-27-2008
    Location
    Manila, Philippines
    Posts
    20

    Loop for all Worksheets

    hELP ME SO i CAN run THIS codeS to all worksheets in the activeworkbook AT ONE TIME,(e.i. Oct 2008). I record this macro IN my Personal macros as 'Macro5.'
       Windows("IDF Clearing Template REVISED.xls").Activate
        Rows("1:2").Select
        Range("BE1").Activate
        Selection.Copy
        Windows("Oct 2008.xls").Activate
        Rows("1:1").Select
        Range("BG1").Activate
        Selection.Insert Shift:=xlDown
        Windows("IDF Clearing Template REVISED.xls").Activate
        Columns("BM:BQ").Select
        Application.CutCopyMode = False
        Selection.Copy
        Windows("Oct 2008.xls").Activate
        Application.WindowState = xlMinimized
        Columns("BM:BM").Select
        ActiveSheet.Paste
        Range("BN2").Select
        Application.Run "'IDF Clearing Template REVISED.xls'!Macro1"

    Thanks and best regards
    Last edited by royUK; 12-08-2008 at 11:41 AM.

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284
    Is this what you want?

    Dim sh As Worksheet
    Dim target As Worksheet
    
        Set target = Workbooks("Oct 2008.xls").Worksheets(1)
        For Each sh In Workbooks("IDF Clearing Template REVISED.xls")
        
            sh.Range("BE1").Copy
            target.Range("BG1").Insert Shift:=xlDown
            sh.Columns("BM:BQ").Copy target.Columns("BM:BM")
            SHRange("BN2").Select
            Application.Run "'IDF Clearing Template REVISED.xls'!Macro1"
        Next sh

  3. #3
    Registered User
    Join Date
    11-27-2008
    Location
    Manila, Philippines
    Posts
    20
    HI.

    my working file is the 'Oct 2008.xls'. In each Worksheet, I want to run the the 'macro5' located in my "Personal Macros.bas".

    Thanks

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Is this whay ytou mean, place the code in the workbook you are using

     Dim ws     As Worksheet
    
        For Each ws In ThisWorkbook.Worksheets
            Application.Run "'Personal.xls'!Macro5"
        Next ws
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Registered User
    Join Date
    11-27-2008
    Location
    Manila, Philippines
    Posts
    20
    Quote Originally Posted by royUK View Post
    Is this whay ytou mean, place the code in the workbook you are using

     Dim ws     As Worksheet
    
        For Each ws In ThisWorkbook.Worksheets
            Application.Run "'Personal.xls'!Macro5"
        Next ws

    Hi. The Macro5 codes only works for active worksheet not for the rest of all non-empty worksheets.

    Thanks.

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Your post does not comply with Rule 3 of our Forum Rules. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here http://www.excelforum.com/misc.php?do=bbcode#code

    Note: I will add them this time only!

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Then you either need to amend macro5 to work efficiently to suit your needs or amend my code to actually select each sheet, which will of course be slower & less efficientr

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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