+ Reply to Thread
Results 1 to 6 of 6

Extra rows being hidden in loop to hide rows

  1. #1
    Registered User
    Join Date
    02-13-2012
    Location
    Dublin
    MS-Off Ver
    Excel 2010
    Posts
    22

    Extra rows being hidden in loop to hide rows

    Hi,

    I am working on a VBA application. It's nearly finished and I have to acknowledge the help I have got on a couple of problems already from StephenR, SixthSense and AndyLitch. All the problems relate to VBA syntax and the specific manner in which loops are coded. I have one more problem and I hope that some VBA coding expert out there will be able to quickly spot what's causing the problem.

    I am attaching a slimmed down version of the application which illustrates the problem.

    Here we are starting with a small range of Type 2 records (just 3 of them). We also have 2 small tables (for Business Units and Roles).

    When the 'Synch Tables' routine is run, a row is inserted for all possible combinations of Business Unit and Role (4 x 3 = 12 in this illustration). The inserted rows are set to be 'Type 1' records and the intention is that all of the Type 1 rows are hidden when the Synch Tables routine has completed.

    When the Synch Table routine is re-run, all existing Type 1 records are deleted and a new set is added. This all works fine.

    The problem is that 12 exrta rows are being hidden every time the routine is run and I can't figure out why this is happening. It's driving me crazy !!!

    I know this has to be something really simple and I suspect again it must be some little piece of VBA syntax that I am missing. I am not a programmer so I struggle at times with this type of problem.

    I am hoping that someone can spot the problem so that I can put the application back on track and get it finished.

    Many thanks,


    GTOL
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Extra rows being hidden in loop to hide rows

    Every time you run the main code, you are calling the macro name "Call PrStandardSetUp" which in turn is also calling another code called "Call PrHideType1Rows" This code hides the row. I suggest you should disable it and run it on its own if you want.

  3. #3
    Registered User
    Join Date
    02-13-2012
    Location
    Dublin
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Extra rows being hidden in loop to hide rows

    Many thanks for your reply AB33 but I still have the problem.
    The intention is to hide the Type 1 rows after the synch has been done.

    Regardless of whether I run PrHideType1Rows in the current manner or on its own as you suggest, the additional rows are being hidden and I have no idea why this is happening. Can you try the following for me please just so you can replicate the problem.

    Commnent out 'Call PrHideType1Rows'
    Get back to the starting positon by manually deleting all Type 1 rows
    You should now just have 3 rows of Type records

    Run the synch
    You should see 15 rows (3 x Type 2 plus 12 x Type 1) - this is what should happen

    Next we want to hide the Type 1 rows so run the PrHideType1 macro
    This hides the 12 x Type1 rows and just shows the Type 2 rows - again this is what should happen

    Now run the synch again
    There will be no change in the underlying data - we will just have the same set of Type 1 data overwriting the original set

    Run the Hide macro again
    This time an extra 12 rows are hidden (between row 4 and 29) and only 1 of the Type 2 rows is shown.

    Each time I re-run the synch & hide, an extra 12 rows are hidden and only one of the Type 2 rows is shown.

    I am looking to hide the Type 1 rows and only show the Type 2 rows each time the synch routine is run. I don't want any extra rows hidden.

    Can you spot the problem ?


    GTOL

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Extra rows being hidden in loop to hide rows

    Try the attached
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    02-13-2012
    Location
    Dublin
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Extra rows being hidden in loop to hide rows

    Great. That works.

    I actually simplified it a good bit by unhiding all PrData rows at the start using a simple 'PrData.EntireRow.Hidden = False' statement. This avoids having 2 loops, one to Unhide and another to Hide again.

    Thanks a million for taking the time out to help me anyway.
    Much appreciated

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Extra rows being hidden in loop to hide rows

    gtol,
    I was going to suggest the same, but I was not sure if the code was corrected in the first place. You have cracked it yourself-Well done!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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