Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Alma Austin   on Oct 29 In MS Office Category.

  
Question Answered By: Saila Iqbal   on Oct 29

Two coding errors leap out, and either could be causing problems:

1) You use Sheet1. and Sheet13. prefixes on most statements, but you do not
use them on the statements that actually hide/unhide the rows. That means
that it is going to hide/unhide the rows in whatever happens to be the
active sheet at the time  you run  the code. I assume you should actually be
changing the rows in Sheet13.

2) Your second While loop runs to an end  tag, then your third While loop
runs out to </5lane>. It should not run the third loop when etag is set to
</5lane>.

Whether either of these is contributing to your current problem, I don't
know.

Also, you use the ActiveSheet. prefix on the protect/unprotect statements.
Presumably this should be Sheet13.

What puts the > 0 values into the Sheet1 cells?

As David G says, there is an easier way to do what you want. (Or at least
make it more readable anyway.) Use a subroutine to do the scan and hide,
and give it the number of the section that you want to make visible. Also,
restructure the first part of the code  to use IF / ELSE IF to select just
the one action you want to perform. For instance, you could write the first
part of the code as

If Sheet1.Cells(24, 1) > 0 Then
Call MakeVisible (5)
ElseIf Sheet1.Cells(23, 1) > 0 Then
Call MakeVisible (4)
ElseIf Sheet1.Cells(22, 1) > 0 Then
Call MakeVisible (3)
ElseIf Sheet1.Cells(21, 1) > 0 Then
Call MakeVisible (2)
ElseIf Sheet1.Cells(20, 1) > 0 Then
Call MakeVisible (1)
End If

assuming you really do want section 5 to take precedence over section 4,
etc, as in your code.

Share: 

 

This Question has 10 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Code slows down after running once Or get search suggestion and latest updates.


Tagged: