+ Reply to Thread
Results 1 to 7 of 7

Loop through all worksheets in workbook to perform action fix code

  1. #1
    Registered User
    Join Date
    11-07-2013
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    51

    Loop through all worksheets in workbook to perform action fix code

    I have tried both of the codes below to Loop through each worksheet in my workbook and select cells.

    I know it seems as though that is trivial, but as many people use the file, and the function of the file is to create a quick request, starting at the input cell is crucial.

    That being said, the codes below are only running on the currently viewed worksheet, it's not actually looping through to perform the task. I have tried two versions based on research, and I cannot get either to perform task on each worksheet, please point out the error I am missing so I can get this up and running. Thanks in advance.

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Loop through all worksheets in workbook to perform action fix code

    For your first code:
    Please Login or Register  to view this content.
    I'm interested in starting a career working with VBA, if anyone knows of any opportunities!

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Loop through all worksheets in workbook to perform action fix code

    try to edit this line
    Please Login or Register  to view this content.
    to be
    Please Login or Register  to view this content.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  4. #4
    Registered User
    Join Date
    11-07-2013
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    51

    Re: Loop through all worksheets in workbook to perform action fix code

    I get an error message.

    Runtime error 1004
    Select method of Range class failed.

  5. #5
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Loop through all worksheets in workbook to perform action fix code

    so you should activate ws first
    Please Login or Register  to view this content.
    before the line
    Please Login or Register  to view this content.
    But it is not recommended to select or activate sheets or ranges .. you may tell us what do you want to achieve ..
    You can achieve your task without activating or selecting
    For example: you can put sheet's name in range("A1") in all sheets like this
    Please Login or Register  to view this content.
    Last edited by YasserKhalil; 01-08-2016 at 12:17 PM.

  6. #6
    Registered User
    Join Date
    11-07-2013
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    51

    Re: Loop through all worksheets in workbook to perform action fix code

    That is exactly the solution I needed. It worked like a charm.

    Just as a background, each user of this workbook enters a file number in cell I3 and it pulls all pertinent information from a second file, then the user changes anything that needs updated, prints and emails a PDF of the file to the proper person. All of this is achieved with a macro. often times we change other parts of the sheet to fit a specific customer requirements, but I need the I3 cell to be selected on all sheets every time we open the workbook so that the user isn't starting at a different place of the sheet each time. It is to be a time saver, and for lack of better reason/term, needs to be idiot proof. If I tell a user to open workbook and enter file number in I3 and for the first 20 times it's the cell already selected, then on the 21st time we have had problems explaining to a novice user that they have to manually select the cell, since almost all of it is auto populated.

    The reason for the Macro is to have minimal training needed to begin using the workbook. Thank you for your help again.

  7. #7
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Loop through all worksheets in workbook to perform action fix code

    You're welcome. Glad I can help
    Thanks for the fedback

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Perform specific action if workbook is opened under special circumstances
    By ks100 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-13-2015, 02:55 PM
  2. [SOLVED] VBA code to create a workbook and copy or move worksheets in to workbook through loop
    By anishkumarvs in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-16-2015, 05:40 AM
  3. [SOLVED] VBA Code to Perform action only if sum of cells are greater than 0
    By cb10 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-26-2012, 08:15 PM
  4. [SOLVED] Perform action on select sheets upon opening workbook
    By newrui in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-22-2012, 03:03 PM
  5. Loop through Autofilter Multiple Criterias and perform action
    By tahatkhan in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 03-22-2012, 04:07 PM
  6. Perform action on every workbook in a directory
    By Btibert in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-06-2006, 03:33 PM
  7. How to perform action in all worksheets
    By Sethaholic in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-11-2005, 02:44 PM

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