![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: Arizona
Posts: 72
|
I'm a VBA rookie so I apologize if this is a simple procedure. What kind of code should I use to have a sheet automatically hide rows where the value in the column T for that row is "Y"? Can this always be running so that if "Y" changes to "N", the row is no longer hidden? Thanks.
|
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Feb 2002
Location: Houston,Texas
Posts: 418
|
Does it have to be VBA? You could do this without VBA by using DATA VALIDATION.
__________________
Veni, Vidi, Velcro - I came, I saw, I stuck around Taxation WITH representation ain't so hot either |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Location: Arizona
Posts: 72
|
how, i'm all ears for suggestions. Thanks!
|
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Feb 2002
Location: Houston,Texas
Posts: 418
|
Sorry, I meant Conditional formatting. Select the first cell of your first row of data. I'm assuming A1 for this example. Choose FORMAT > Conditional formatting.
Change Cell value is to Formula is and put =$T1="Y" in the formula box. then click on format and set the font color to the same as the background color for the cell. Click OK twice. Copy the cell and then paste Special Format to all the cells in that row you want to format.When there is a Y in column T the data in that row will be "invisible". You can copy the format to all the cells in your range. This formula will only hide data when col T is = Y or y. If you only want it to be visible if the user puts an N in col T use =$T1<>"N" for the formula
__________________
Veni, Vidi, Velcro - I came, I saw, I stuck around Taxation WITH representation ain't so hot either |
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Feb 2002
Location: Arizona
Posts: 72
|
but I actually need to hide the rows, not just the text in the row. The formula in the T column recognizes that there is nothing in the row accomplished with my if statement retuning a "Y" (or "N" if there is somehthing in the row and it shouldn't be hidden - ie should be printed.)
I need the sheet to shrink down horizontally as much as possible automatically - not just hide the text from view. Sorry I should have clarified. I wish conditional formatting included "Hide Row" as a condition, but it doesn't seem to. Thanks for your suggestion, though. |
|
|
|
|
|
#6 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Winnipeg
Posts: 2,330
|
Quote:
Private Sub Worksheet_Change(ByVal Target As Excel.Range) Select Case Range("T" & Target.Row).Value Case Is = "Y" Target.EntireRow.Hidden = True Case Is = "N" Target.EntireRow.Hidden = False End Select End Sub Regards,
__________________
Barrie Davidson "You're only given a little spark of madness. You mustn't lose it." - Robin Williams |
|
|
|
|
|
|
#7 |
|
Board Regular
Join Date: Feb 2002
Location: Arizona
Posts: 72
|
thanks this is awesome and I think very close, but it only works if I manually enter "N" or "Y". The values "Y" and "N" in column T are determined when data is entered in another sheet. Should I have a Worksheet_Calculate instead of Worksheet_Change? How should I change this to work? Thanks again.
|
|
|
|
|
|
#8 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Winnipeg
Posts: 2,330
|
Quote:
Code:
Private Sub Worksheet_Activate()
For Each c In Range("T1", Range("T65536").End(xlUp).Address)
Select Case c.Value
Case Is = "Y"
c.EntireRow.Hidden = True
Case Is = "N"
c.EntireRow.Hidden = False
End Select
Next c
End Sub
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Select Case Range("T" & Target.Row).Value
Case Is = "Y"
Target.EntireRow.Hidden = True
Case Is = "N"
Target.EntireRow.Hidden = False
End Select
End Sub
__________________
Barrie Davidson "You're only given a little spark of madness. You mustn't lose it." - Robin Williams |
|
|
|
|
|
|
#9 |
|
Board Regular
Join Date: Feb 2002
Location: Arizona
Posts: 72
|
This works in the hide direction. But if I add data on the data sheet, I also need the code to recognize that the value in T (although hidden) has changed from "Y" to "N" and then unhide the row. Thanks.
|
|
|
|
|
|
#10 |
|
Board Regular
Join Date: Feb 2002
Location: Houston,Texas
Posts: 418
|
How about an Autofilter?
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|