Hide cell value if another cells value =

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,227
Office Version
  1. 2007
Platform
  1. Windows
Hi,
I would like to hide a cell value if a specific cell value contains a specific word.
Cell M11 is a drop down with two options CAre or BIKE
If CAR is selected then i wish to hide the values in cells O14 & O17

Trying with the code below i am being today doesnt support support this property or method with the line shown in Red

Rich (BB code):
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  If Range("M11").Value = "CAR" Then
  Range ("O14").Visible = False
    End If
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
It is not possible to hide the cell value, since the cell does not have that property.

What you can do is change the cell color to white (for example) and the font color to white as well. That will create an "invisible" effect.

Before:
1691696530822.png

After:
1691696554113.png

For the above, replace your code with the following:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Address = "$M$11" Then
    If Target.Count > 1 Then Exit Sub
 
    With Range("O14,O17")
      If Target.Value = "CAR" Then
        .Interior.Color = vbWhite
        .Font.Color = vbWhite
      Else
        .Interior.Color = xlNone
        .Font.Color = vbBlack
      End If
    End With
  End If
End Sub


-------------------------
There is a detail, if you select cell O14, the value is "hidden" in the cell, but in the formula bar you will see the value:
1691697062208.png


If you also want to hide the value in the formula bar. Then do the following:

Select the sheet where you want this to work, and run this macro only once:
VBA Code:
Sub prepare_sheet()
  ActiveSheet.Unprotect
  Cells.Locked = False
  Cells.FormulaHidden = False
  With Range("O14,O17")
    .FormulaHidden = True
  End With
  ActiveSheet.Protect
End Sub

What the macro does is:
- Unlock all the cells.​
- Change the Hidden option only to cells O14 and O17.​
- At the end, the macro protects the sheet, so that the above takes effect.​

Now if you select cell O14 the value is hidden in the cell and in the formula bar:
1691697550773.png

🤗

Regards
Dante Amor
 
Last edited:
Upvote 0
Thanks.
Will look at that tomorrow.
So just a question for now.

My worksheet is coloured grey.
I can find the #????? Reference but can I use it in place of vbWhite?

.Interior.Color = vbWhite
 
Upvote 0
I can find the #????? Reference but can I use it in place of vbWhite?
For example:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Address = "$M$11" Then
    If Target.Count > 1 Then Exit Sub
    
    With Range("O14,O17")
      If Target.Value = "CAR" Then
        .Interior.Color = 12566463
        .Font.Color = 12566463
      Else
        .Interior.Color = 12566463
        .Font.Color = vbBlack
      End If
    End With
  End If
End Sub

Ex:
1691709338760.png


:cool:
 
Upvote 0
Solution

Forum statistics

Threads
1,215,446
Messages
6,124,896
Members
449,194
Latest member
JayEggleton

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