VBA code to hide rows

mgchurch77

New Member
Joined
Aug 15, 2011
Messages
33
Description of the worksheets:

For simplicity sake I'll describe my workbook as only having two worksheets.

A "source" worksheet and a "destination" worksheet. The "source" worksheet consists of column A which are names of customers and column B consists of the result of a calculation fusing data from other sheets which could be any number from 1-12.

The "destination" sheet has a certain cell (we'll call that the target cell) where the user "me" can input a number from 1-12. Column A of the destination page matches the number from the target cell to column B of the source page to determine whether or not to pull the customer name from column A of the source page into column A of the destination page. If the number from the target cell matches column B of the destination page, the name is pulled, if there is not a match the answer returned is false.

Code needed:

The code would run on the destination page as outlined above. What I need it to do is to hide the rows where the answer for that certain row in column A of the destination page is "false". Thanks in advance for anyone's help.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi mgchurch77,

Didn't read your post entirely but this code hides a row if it reads a "False"
You can add a sheets("name" before the cells if the cell is on another sheet.

Good luck


Code:
Private Sub CommandButton1_Click()
Dim row As Integer, col As Integer

col = 3

For row = 1 To 10
    If Cells(row, col).Value = "False" Then
        ActiveSheet.Rows(row).Hidden = True
    Else
        ActiveSheet.Rows(row).Hidden = False
    End If

Next

End Sub
 
Last edited:
Upvote 0
Thanks evnoort, however the code didn't seem to do anything. I did change the column # in the code to 1 and the range of rows to 1:700. I also noticed that this code references a command button which I do not have nor do I want. Any other ideas.
 
Upvote 0
mgchurch77,

Give the following a try:
Code:
Sub tgr()
    Dim rngFalse As Range
    With Intersect(Sheets("destination").UsedRange, Sheets("destination").Columns("A"))
        .AutoFilter 1, False
        On Error Resume Next
        Set rngFalse = .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible)
        .AutoFilter
    End With
    If Not rngFalse Is Nothing Then rngFalse.EntireRow.Hidden = True
End Sub



Hope that helps,
~tigeravatar
 
Upvote 0
Thanks tigeravatar. Still nothing. I changed the "destination" sheet reference to "Target List Report" which is the actual name of the "destination" sheet. Other than that, I posted the code directly to the sheet and doesn't seem to do anything.
 
Upvote 0
FYI, I guess the code could do a "hide" instead of a delete if easier. As long as the hide would hide from printing as well.
 
Upvote 0
Try something like this....

Code:
Sub HideFalse()

Col = 1
With ActiveSheet
Application.ScreenUpdating = False

  For r = 1 to 700
      If .Cells (r,Col).Value = FALSE Then .Cells(r,Col).EntireRow.Hidden = True
  Next r
Application.ScreenUpdating = True

End With

End Sub


To Unhide....
Code:
Sub UnhideFalse ()
ActiveSheet.Range("A1:A700").EntireRow.Hidden = False
End Sub

I have assumed that the FALSE is Boolean and not "False" as a string.
If you do not want a control button then assign keyboard shortcuts.
NB. Code needs to reside in a Module.
 
Last edited:
Upvote 0
I have just thought.
If you assign a shortcut you will want to change 'ActiveSheet' to Sheets("Target List Report") so that you do not accidently process the the wrong sheet.

Alternatively, add this at the start of the code....

If Not ActiveSheet.Name = "Target List Report" Then Exit Sub
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,827
Members
452,946
Latest member
JoseDavid

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