+ Reply to Thread
Results 1 to 7 of 7

Checking a Model List against the Worksheets in the Workbook

  1. #1
    Registered User
    Join Date
    08-08-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    5

    Checking a Model List against the Worksheets in the Workbook

    I have a macro that works fairly well for smaller projects, but when the list of models is longer than ~30, the loop to check for the worksheets with the model names gets really slow. My current project has 72 models, and every time I want to do a model list check, I have to wait multiple minutes. Does anyone have any advice to speed up this process?

    Please Login or Register  to view this content.

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Checking a Model List against the Worksheets in the Workbook

    Why not create global object (ex. Scripting.Dictionary), which holds all existing worksheet names when the workbook is opened.

    Then use it to check if Model Name exists.

    But what should happen if there isn't sheet with model name? Should it be created? Or just leave column B blank?

    It'd be easier to help you if you upload sample workbook that demonstrates your need and set up.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,616

    Re: Checking a Model List against the Worksheets in the Workbook

    Dictionary is a good idea.
    Even simple array could be used for it.
    See sample code below (I assumed that there are two options: "Created" or just empty cell in column B).
    See the code:
    Please Login or Register  to view this content.
    Best Regards,

    Kaper

  4. #4
    Registered User
    Join Date
    08-08-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    5

    Re: Checking a Model List against the Worksheets in the Workbook

    Thank you both for your advice in this case. I actually reordered the logic to go worksheet by worksheet and check the rows and it significantly improved the speed.
    Please Login or Register  to view this content.
    I am relatively inexperienced in VBA so I am not sure how the Scripting.Library function works. Can someone elaborate on that function?

  5. #5
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Checking a Model List against the Worksheets in the Workbook

    On second thought, I'd recommend using IsObject to check if sheet exist in workbook (trick I learned from Marc L @ chandoo.org forum).

    And using array to loop through range. Something like below.

    Please Login or Register  to view this content.
    Last edited by CK76; 02-12-2018 at 11:57 AM.

  6. #6
    Registered User
    Join Date
    08-08-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    5

    Re: Checking a Model List against the Worksheets in the Workbook

    CK76,
    Awesome! Compared to both of my previous methods, your code is instantaneous. Thank you so much for sharing!

  7. #7
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Checking a Model List against the Worksheets in the Workbook

    You are welcome and thanks for the rep

+ 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. Replies: 8
    Last Post: 11-11-2015, 01:33 PM
  2. [SOLVED] Create New Worksheets and Rename Them according to List in Another workbook
    By Hackboss007 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-12-2014, 11:07 AM
  3. List All Worksheets in Workbook
    By sparx in forum Excel General
    Replies: 8
    Last Post: 11-11-2013, 06:30 PM
  4. Replies: 2
    Last Post: 01-25-2006, 04:55 PM
  5. [SOLVED] Can I print a list of all of the worksheets within a workbook?
    By SRsonn in forum Excel General
    Replies: 1
    Last Post: 06-29-2005, 03:05 PM
  6. [SOLVED] view list of worksheets contained within a workbook
    By michael in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-09-2005, 05:06 PM
  7. Can I see a list of the worksheets within a workbook without scro.
    By shrn in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-25-2005, 10: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