macro that hides rows

plost33

Well-known Member
Joined
Oct 2, 2008
Messages
866
I have the following macrothat I just cannot seem to finish up. the code is suppost to hide all rows where the cell value in the range of B4:B49 is blank/empty/nothing. If nothing is in the cell then that row is hidden. but I am not sure whats wrong but it is just not working. here what I have so far:


Code:
Application.ScreenUpdating = False
Sheets("well access").Cells.EntireRow.Hidden = False
Worksheets("well access").Activate
With ActiveSheet
cnt1 = WorksheetFunction.CountIf(.Range("B4:B49"), "")
End With
Sheets("well intervention").Cells.EntireRow.Hidden = False
Worksheets("well intervention").Activate
With ActiveSheet
cnt2 = WorksheetFunction.CountIf(.Range("B4:B49"), "")
End With
Sheets("TA").Cells.EntireRow.Hidden = False
Worksheets("TA").Activate
With ActiveSheet
cnt3 = WorksheetFunction.CountIf(.Range("B4:B49"), "")
End With
Sheets("PA").Cells.EntireRow.Hidden = False
Worksheets("PA").Activate
With ActiveSheet
cnt4 = WorksheetFunction.CountIf(.Range("B4:B49"), "")
End With
Sheets("Non Productive").Cells.EntireRow.Hidden = False
Worksheets("Non Productive").Activate
With ActiveSheet
cnt5 = WorksheetFunction.CountIf(.Range("B4:B49"), "")
End With
Worksheets("code Totals (hidden)").Activate
cnt = WorksheetFunction.Sum(cnt1 + cnt2 + cnt3 + cnt4 + cnt5)
 
For S = 1 To 5 '1 to number of sheets, eg 5 in this example
Select Case S
Case 1: ShtName = "Well Access" 'Type the names of each sheet (in "")
Case 2: ShtName = "Well Intervention"
Case 3: ShtName = "TA"
Case 4: ShtName = "PA"
Case 5: ShtName = "Non Productive"
End Select 'Make sure the no of Case's is the same as max S
Set Sht = Worksheets(ShtName)
For lngRow = 4 To 49   'Rows 4 thru 49
With Sht
For r = 4 To 49 Step 1 ' HIDES ROWS WITH NOTHING IN "B"
    If Range("B" & r).Value = "" Then
        Rows(r).EntireRow.Hidden = True
    End If
changecount = changecount + 1
pctDone = changecount / cnt
       With UserForm1
            .FrameProgress.Caption = Format(pctDone, "0%")
            .LabelProgress.Width = pctDone * (.FrameProgress.Width - 10)
        End With
        'The DoEvents statement is responsible for the form updating
        DoEvents
Next r
End With
Next lngRow
Next S
   Unload UserForm1
Set Sht = Nothing

Application.ScreenUpdating = True
MsgBox "Phase sheets have been updated!"
End Sub




some parts of this code are used for updating a userform progress bar.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,214,622
Messages
6,120,580
Members
448,972
Latest member
Shantanu2024

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