Monika,
Application.ScreenUpdating simply turns off the re-painting of the Excel
window when your code makes a change, for speed. It is perfectly okay to do
this, as long as you re-set at the end, so you see the final sum of changes.
As to what the code does, here is a quick synopsis
- firstly it checks if the workbook is protected, and exit if so
- then it adds a dialog sheet, which is an old style form, but still
maintained in Excel
- then we have a loop that goes through the data and determines which items
that fit our criteria, and adds a control to our new dialog sheet for each
required item. In this case, we pick out each worksheet and add an option
button, although I have given other suggestions that check all open
workbooks, and add checkboxes. I added optionbuttons as you can only
activate one sheet per your requirement, and only one option button can be
selected at a time, whereas many checkboxes can be selected
- it then resizes the dialog accordingly to how many controls are on it, and
adds a title
- then it forces the focus onto the OK button (a bit of magic here, but
obscure)
- then it shows the dialog so that you the user can make your choice
- a loop is run which checks which option is selected, and activates the
sheet associated with that option
- finally, it deletes the dialog
Methinks you apologise too much (that is a joke, not a criticism). Tom made
a perfectly valid point, and I added to that point. I got this idea from
John Walkenbach, but I did change it including stripping the comments
(partly to assist me making the changes, partly as I explained in a later
posting). Although I wouldn't go so far to say that this is all John's idea,
these things are rarely one person's work they usually are the culmination
of many inputs, but John refined it, and published a very nice working
solution on his site. I have acknowledged this previously, and it is good to
acknowledge, although I cannot promise that I will always acknowledge where
I get these ideas from, but I do try.
I like questions such as you post, this one has led me to create a generic
solution that I can easily adapt to many problems, and I get the feeling you
are learning lots, so keep it up, you'll get tons of support here.
--
HTH
Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)