Hide or unhide a cell base on text in a different cell - Either VBA or formula solution.

Liam_1988

New Member
Joined
Apr 30, 2020
Messages
21
Office Version
  1. 2013
Platform
  1. Windows
Hi,

I've been using VBA for about 6 months or so (hobbyist). I'm currently working on a workbook for my job and I'm completely stuck.

XABCD
1​
Sent By:
2​
Date Sent:
3​
Method:Tracking #:

I have the above in place. I'm trying to have it so that C3 & D3 are hidden unless B3 (which has a Data Validation list assigned to it) says "Postal".

I don't mind if this achieved with a Formula or VBA.

Please Please help it's driving me crazy!
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,831
Office Version
  1. 365
Platform
  1. Windows
You cannot hide individual cells, only entire rows/columns.
 

Liam_1988

New Member
Joined
Apr 30, 2020
Messages
21
Office Version
  1. 2013
Platform
  1. Windows
You cannot hide individual cells, only entire rows/columns.
Ok thanks Fluff.

Assume then that I moved C3 down to become A4 and hide row 4 unless B3 contained "Postal".
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,831
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address(0, 0) = "B3" Then
      Rows(4).Hidden = Not Target.Value = "Postal"
   End If
End Sub
This needs to go in the relevant sheet module.
 

Liam_1988

New Member
Joined
Apr 30, 2020
Messages
21
Office Version
  1. 2013
Platform
  1. Windows

ADVERTISEMENT

Thanks Fluff.

Unfortunately there was an error with "If Target.CountLarge > 0 Then Exit Sub".
 

Liam_1988

New Member
Joined
Apr 30, 2020
Messages
21
Office Version
  1. 2013
Platform
  1. Windows
Is there command that's basically if B3 = postal then unhide otherwise hide in any other circumstance.

If it helps the only other cell values can be:
- "Email"
- "Portal"
or Blank
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,831
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Unfortunately there was an error with "If Target.CountLarge > 0 Then Exit Sub".
Why did you change what I supplied?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,831
Office Version
  1. 365
Platform
  1. Windows
You said you were getting an error on this line "If Target.CountLarge > 0 Then Exit Sub"
That is not what I suggested.
What is the code you are using?
 

Liam_1988

New Member
Joined
Apr 30, 2020
Messages
21
Office Version
  1. 2013
Platform
  1. Windows
I tried:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Target.Address(0, 0) = "D83" Then
Rows(87).Hidden = Not Target.Value = "Postal"
End If
End Sub

and

If Target.CountLarge > 1 Then Exit Sub
If Target.Address(0, 0) = "D83" Then
Rows(87).Hidden = Not Target.Value = "Postal"
End If
End Sub
You said you were getting an error on this line "If Target.CountLarge > 0 Then Exit Sub"
That is not what I suggested.
What is the code you are using?
 

Watch MrExcel Video

Forum statistics

Threads
1,130,089
Messages
5,640,048
Members
417,124
Latest member
Herostrata

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
Top