Consulting

Results 1 to 6 of 6

Thread: Solved: Loop in Excel

  1. #1
    VBAX Regular
    Joined
    Jan 2007
    Posts
    28
    Location

    Solved: Loop in Excel

    I want to manipulate some data on all worksheets in a particular workbook except the last 6 sheets. The number of worksheets will not be constant. Could someone help with the code to do this? Thanks.

  2. #2
    VBAX Regular
    Joined
    Oct 2006
    Location
    Warsaw, Poland
    Posts
    23
    Location
    Hi,

    Quote Originally Posted by ssinghal
    I want to manipulate some data on all worksheets in a particular workbook except the last 6 sheets. The number of worksheets will not be constant. Could someone help with the code to do this? Thanks.
    Use something like that:

    For Xi=1 to Worksheets.Count - 6
     
    'your code here for Sheets(Xi)
     
    Next Xi
    One Hundred MS Excel Games

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [vba]For i = 1 To Sheets.Count - 6
    Sheets(i).Range("A1")=2
    Next
    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    VBAX Regular
    Joined
    Jan 2007
    Posts
    28
    Location
    How do I make it go to the next worksheet? It is performing my action on the first sheet everytime.

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    My code should enter a value on each sheet except the last six. Can you post your code?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    VBAX Regular
    Joined
    Jan 2007
    Posts
    28
    Location
    I figured it out. I needed Sheet(i).Select in my code.
    Thanks.

Posting Permissions

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