VBA Help - Auto Hide Row

Golfpro1286

New Member
Joined
Aug 22, 2018
Messages
30
Hello, I have looked around and could not find any VBA that would work for what I am trying to do, which seemed like it should be simpler than it is turning out to be. I want to automatically hide and unhide some rows based on the following:

I have a summary sheet (in "Sheet 1") that summarizes the number of loans an officer makes within a given system. I want to hide/un-hide any rows with "0". Example:
RowNameCount
1Adam1
2Corey0
3Trevor1
4Jim0
5Randy0


<tbody>
</tbody>

Here is how the count is calculated:

The loan data is entered into a table on a separate sheet ("Sheet 2") as follows:

OfficerLoan #System
Adam1234CL
Adam5678CL
Corey91011IL
Trevor8765ML
Jim5843CL
Jim4128IL
Randy6634ML

<tbody>
</tbody>

In "Sheet 1" I have a combo box to change the system between "CL" "IL" and "ML"
The count column is calculated from a COUNTIFS formula that will use data from table on "Sheet 2" to count number of loans for the system selected in the combo box.

My expected results here would be as follows:
If CL is selected in the combo box rows 2,3,5 would auto-hide because the value would be 0 and rows 1,4 would auto un-hide becuase their value would be greater than 0.

If IL is selected in the combo box rows 1,3,5 would auto-hide because the value would be 0 and rows 2,4 would auto un-hide becuase their value would be greater than 0.

If ML is selected in the combo box rows 1,2,4 would auto-hide because the value would be 0 and rows 3,5 would auto un-hide becuase their value would be greater than 0.

Thanks for any help!
 

kevatarvind

Well-known Member
Joined
Mar 3, 2013
Messages
1,039
Hello Try Below Code Paste it on Sheet Module Assuming Your Criteria Column is "C"
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim i As Integer
    Dim rng As Range
    lr = ActiveSheet.Range("C:C").Find(what:="*", searchdirection:=xlPrevious, searchorder:=xlByRows).Row
    For i = 2 To lr
        If Cells(i, 3).Value = 0 Then
            Set rng = Application.Range("C" & i)
            rng.EntireRow.Hidden = True
        ElseIf Cells(i, 3).Value > 0 Then
            Set rng = Application.Range("C" & i)
            rng.EntireRow.Hidden = False
         End If
    Next
End Sub
 
Last edited:

Akuini

Well-known Member
Joined
Feb 1, 2016
Messages
2,267
Office Version
2013
Platform
Windows
The count column is calculated from a COUNTIFS formula that will use data from table on "Sheet 2" to count number of loans for the system selected in the combo box.
Could you show us the formula?
 

Forum statistics

Threads
1,078,516
Messages
5,340,879
Members
399,396
Latest member
PBE

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top