Hiding Rows Based on Text

geotek

New Member
Joined
Feb 17, 2015
Messages
5
I'm hopeful that someone can help with this question. I'm not good with VBA but trying to learn.

I have a spreadsheet that gets periodic updates from a secondary program. I import the data onto Sheet3 and do some misc. edits (i.e., unmerge cells, and sort the data columns based on 2 fields). Generally I have between 300 and 400 rows (Varies) and 39 columns (Static). The Sheet1 references 3 of the columns from Sheet3 (Client ID; Status; Days at Status; and Notes) and graphs them. The data is sorted according to "Status" and then "Days at Status" for the graph to display correctly. I've created a example table.


Excel 2007
ABCD
1Client NoCurrent StatusDays at StatusNotes
2Client 001Status 11Follow up
3Client 002Status 12Follow up
4Client 003Status 14Follow up
5Client 004Status 110Follow up
6Client 005Status 110Follow up
7Client 006Status 112Follow up
8Client 007Status 115Follow up
9Client 008Status 23Pending Response
10Client 009Status 25Pending Response
11Client 010Status 25Pending Response
12Client 011Status 27Pending Response
13Client 012Status 214Pending Response
14Client 013Status 221Pending Response
15Client 014Status 223Pending Response
16Client 015Status 233Pending Response
17Client 016Status 34Responded
18Client 017Status 38Responded
19Client 018Status 312Responded
20Client 019Status 312Responded
21Client 020Status 312Responded
22Client 021Status 318Responded
23Client 022Status 319Responded
24Client 023Status 319Responded
25Client 024Status 44To be Closed
26Client 025Status 44To be Closed
27Client 026Status 44To be Closed
28Client 027Status 44To be Closed
29Client 028Status 44To be Closed
30Client 029Status 44To be Closed
Sheet1


I normally don't need to worry about any of the Status 4's so I select them and hide the rows. But every time I get a new data set (weekly or more frequently), i have to unhide the hidden rows and find all of the "Status 4's" again. I want to automate that process with a code. I had a very crude piece of VBA that unhide every row and then went through each row and looked for "status 4" and hid the row. This was very slow, and then I lost the code when the workbook crashed and had to go back to a much earlier version without the VBA. My data set varies in length week to week.

What I hope to accomplish is to have a VBA that will go to the first occurrence of Status 4 and then hide every row to the end of the data in the "Status" column. I expect that there will be additional Status' after "4" in the future but I won't have any need to deal with them for what I'm doing.

I started with this code I found posted, but haven't had much luck getting to where I need to be.

Code:
Sub Find_Last()
    Dim FindString As String
    Dim Rng As Range

    FindString = "Status 3"
    
    If Trim(FindString) <> "" Then
        With Sheets("Sheet1").Range("B:B")
            Set Rng = .Find(What:=FindString, _
                            After:=.Cells(1), _
                            LookIn:=xlValues, _
                            LookAt:=xlWhole, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlPrevious, _
                            MatchCase:=False)
                 
            If Not Rng Is Nothing Then
                Application.Goto Rng, True
             
            Else
                MsgBox "Nothing found"
            End If
        End With
    End If
  
    
End Sub

Thanks for any help!
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hello,

if you truly mean to hide the rows then use

Code:
Sub HIDE_STATUS_4()
    Application.ScreenUpdating = False
    With Sheets("Sheet1")
        .Rows.Hidden = False
        For MY_ROWS = 2 To .Range("B" & Rows.Count).End(xlUp).Row
            If .Range("B" & MY_ROWS).Value = "Status 4" Then
                .Rows(MY_ROWS).Hidden = True
            End If
        Next MY_ROWS
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
I attempted an autofilter originally, but an issue I ran into is that the data is used by a graph. When the autofilter was in place, I still got the filtered rows showing up as blank regions on the graph. Which lead me to hiding the rows. This removed the data completely from the graph and prevented the large blank regions. If there is a way to get the autofilter to not have the blanks show on the graph I'm definitely interested.

During another search after getting the above code, I found this which is what I've adapted:


Code:
Sub HideStatus4()
'---------------------------------------
Dim row_1 As Long: row_1 = 1
Dim row_2 As Long: row_2 = 3000
Dim col As Integer: col = 3     'Col C
'---------------------------------------
On Error GoTo NoNo
row_1 = Application.WorksheetFunction.Match("4 - Payment Issued", Range(Cells(row_1, col), Cells(row_2, col)), 0) + (row_1 - 1)
Rows(row_1 & ":" & row_2).Hidden = True
Exit Sub
'nothing to hide ?
NoNo:
End Sub

This sped up process a great deal. Also, I picked an end range well below the maximum of the anticipated rows and hid to that row. Another issue I had was that the cells that I'm looking into have become references to another sheet which seems to be an issue for the .FIND in my earlier code.
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,941
Members
449,094
Latest member
teemeren

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