Excel VBA for unhiding rows in logical order

mrwad

New Member
Joined
Oct 16, 2018
Messages
49
I have code for Hiding and Unhiding rows in Excel sheet.

Current problem is:

1) Running twice NewUnhideJobs (position of second section)
2) Running once HideAllJobs
3) Running NewUnhideJobs
As the result we have position of third section and not first as it should be. So NewUnhideJobs does not start from 0 but continues to do previous procedure.


Removing of Static counter As Byte was tried but code does not work without it.
counter = 0 was also tried in HideAllJobs without success.

Hiding rows:

Code:
Sub NewUnhideJobs()
Static counter AsByte
    Dim RngTxt AsString, RngAR()AsString, ThisRng AsString


    counter =(counter +1)Mod26

    ThisRng =""&(174-(counter *5))&":"&(174-(counter *5)+4)

    Application.ScreenUpdating =False
    ThisWorkbook.Sheets("Filling form").Unprotect
    ThisWorkbook.Sheets("Filling form").Rows(ThisRng).EntireRow.Hidden =False
    ThisWorkbook.Sheets("Filling form").Protect
    Application.ScreenUpdating =True
EndSub

Unhiding rows:

Code:
Sub HideAllJobs()
   Static counter AsByte
   Application.ScreenUpdating =False
   ThisWorkbook.Sheets("Filling form").Unprotect
   Rows("49:173").EntireRow.Hidden =True
   counter =0
   ThisWorkbook.Sheets("Filling form").Protect
   Application.ScreenUpdating =True
EndSub


P.S. Posted also here https://stackoverflow.com/questions/54881262
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;"></code>
 
Last edited:

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top