![]() |
![]() |
|
|||||||
| 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 |
|
Guest
Posts: n/a
|
I want to use an IF command to hide a cell if it has no value as a way of consolidating my list. I've tried conditional formating but can't find a "hide" selection. Can it be written in code? Any suggestions would be appreciated.
|
|
|
|
#2 |
|
Board Regular
Join Date: Feb 2002
Location: Georgia USA
Posts: 544
|
You can't "Hide" a cell with conditional formatting, but you could change the font color to your sheet color if you don't want to see it.
|
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Posts: 468
|
Yes, almost everything is possible...
if you use vba Use this code and if the entire row is empty, it will be hidden. Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target = "" Then
Rows(Target.Row).Select
If Application.CountA(Selection) = 0 Then
Selection.EntireRow.Hidden = True
End If
End If
End Sub
|
|
|
|
|
|
#4 |
|
New Member
Join Date: Feb 2002
Location: denver
Posts: 7
|
Thank you Bruno, but the rows that I want hidden have "0" values in them. Your code is not working to hide them. I still get something like this:
Market Analysis 0 Advertising 0 0 Sales Etc. If you can help me with this I would appreciate it very much. |
|
|
|
|
|
#5 |
|
New Member
Join Date: Feb 2002
Location: denver
Posts: 7
|
Perhaps my probelem with your code lies in the covnersion. I keep getting an error with this line:
If Target = "A1:A125" Then I'm pretty sure it's because of the target values but not sure how to correct. Please advise. |
|
|
|
|
|
#6 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
|
This should read
If Target.Address = "$A$1:$A$125" then |
|
|
|
|
|
#7 |
|
New Member
Join Date: Feb 2002
Location: denver
Posts: 7
|
Thank you for your help, but the rows are still present after intering the VBA code.
Any suggestions? |
|
|
|
|
|
#8 |
|
Board Regular
Join Date: Feb 2002
Posts: 202
|
just a thought - have you checked that all the cells in the rows are actually empty?
another thought - not sure if this would affect anything, but do you have any merged rows or columns in the target range? [ This Message was edited by: anno on 2002-02-20 19:27 ] |
|
|
|
|
|
#9 | |
|
Board Regular
Join Date: Feb 2002
Posts: 468
|
There was something wrong with the previous posting...
(Juan, you may delete it ?) Quote:
This code doesn't check other columns. Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target = "" Then
Rows(Target.Row).EntireRow.Hidden = True
ElseIf IsNumeric(Target) Then
If Target.Value = 0 Then
Rows(Target.Row).EntireRow.Hidden = True
End If
End If
End Sub
|
|
|
|
|
|
|
#10 |
|
New Member
Join Date: Feb 2002
Location: denver
Posts: 7
|
now I'm getting a script error with my target line:
If Target = "$A$1:$A$125" Then Need I broaden the range or narrow it? |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|