+ Reply to Thread
Results 1 to 11 of 11

Looping through select worksheets

  1. #1
    Registered User
    Join Date
    02-25-2021
    Location
    San Francisco, US
    MS-Off Ver
    2016
    Posts
    10

    Looping through select worksheets

    Hi VBA gurus,

    I'm trying to get my vba to add in a date to certain worksheets in my workbook. The date has to be added to the last blank row on columns A and S. This is the code i have so far but it applies to all worksheets in the workbook..

    How do I get it to exclude certain worksheets by name like "Sheet 1" and "Sheet 3"?

    Please Login or Register  to view this content.
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Last edited by 6StringJazzer; 02-25-2021 at 10:04 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Need help looping through select worksheets

    Your existing code does not apply to all worksheets. It never references a worksheet. Maybe you mean to do this:
    Please Login or Register  to view this content.

    I just addressed the issue of the worksheet and not the rest of your code. You may have other problems. For example, you are populating cells with a string, not a date. The way you are getting the last cell in the column may work but seems a bit overcomplicated.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Looping through select worksheets

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Registered User
    Join Date
    02-25-2021
    Location
    San Francisco, US
    MS-Off Ver
    2016
    Posts
    10

    Re: Need help looping through select worksheets

    Thank you so much for your help, Jeff! Noted on the other problems! Still a newb at VBA so my codes are still v clunky!

    And thanks AlphaFrog for cleaning up the rest of my code - everything worked :D

  5. #5
    Registered User
    Join Date
    02-25-2021
    Location
    San Francisco, US
    MS-Off Ver
    2016
    Posts
    10

    Re: Looping through select worksheets

    Hi Everyone, how do I get the if statement to exclude multiple sheets and not just two?

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Looping through select worksheets

    Just keep adding more choices into the If condition, using And for each one.

    Do you have a naming convention for your sheets that we could take advantage of?

  7. #7
    Registered User
    Join Date
    02-25-2021
    Location
    San Francisco, US
    MS-Off Ver
    2016
    Posts
    10

    Re: Looping through select worksheets

    I tried adding "And" for each one but it gives me an error..

    Let's just say the sheets I'm looking to exclude are called "Small", "Mid","Large","Extra Large" so they have unique names

  8. #8
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,522

    Re: Looping through select worksheets

    Or like this. Less cumbersome by the looks of it
    Please Login or Register  to view this content.
    Saw your last Post too late. Change the names in the exclude line to suit your need.

  9. #9
    Registered User
    Join Date
    02-25-2021
    Location
    San Francisco, US
    MS-Off Ver
    2016
    Posts
    10

    Re: Looping through select worksheets

    Thanks! But I really want to keep the original code using the if and then statements since it allows me to plug in the date just once

  10. #10
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Looping through select worksheets

    To use the date, modify as shown:

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    02-25-2021
    Location
    San Francisco, US
    MS-Off Ver
    2016
    Posts
    10

    Re: Looping through select worksheets

    Thanks so much 6StringJazzer!! That worked perfectly

+ 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. [SOLVED] How to select next visible cell (up) without looping ?
    By karmapala in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-07-2019, 09:56 AM
  2. [SOLVED] Looping and Cell select
    By DeanMcK in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-04-2018, 02:56 AM
  3. Looping using Select Case Statement
    By tdewale in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-07-2017, 09:18 PM
  4. looping select case statement
    By pik in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-08-2008, 08:11 PM
  5. [SOLVED] Looping through Worksheets
    By Steve in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-12-2005, 03:05 PM
  6. Looping across worksheets
    By Ramthebuffs in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-19-2005, 12:52 AM
  7. [SOLVED] Looping through Worksheets
    By Kirk P. in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-07-2005, 02:06 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