Hide columns base on text

Panoos64

Well-known Member
Joined
Mar 1, 2014
Messages
890
Hi all, i would to provide me support so that, when i enter in cell "I4" the text "MONTHLY" should hide automatically the entire columns "D" and "E" and when i change the text to "YEARLY" should unhide the columns. Thank you all in advance
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address(0, 0) = "I4" Then
      Range("D:E").EntireColumn.Hidden = Target = "MONTHLY"
   End If
End Sub
 
Upvote 0
Hi Fluff, it doesn't work but thank you for your support. The cell "I4" contains by default the text "MONTHLY" and so the code should valid this text / word and base on it should hide the columns "D" & "E" and whenever i change the text to "YEARLY" should unhide the related columns. Do not worry if is a complicate function . I can process by manual method. Thanks once again for your support.
 
Last edited:
Upvote 0
Did you put the code the sheet module where you want to hide the columns?
If so, did you change the value in I4
 
Upvote 0
I copied the code into the VBA module but it doesn't run and then i changed the 1st line "Private Sub Worksheet_Change(ByVal Target As Range)" to "Sub Worksheet" and It stops on the below point:
If Target.CountLarge > 1 Then Exit Sub
The message is: "Run-time error 424"
"Object required"

I'm have to write somewhere the name of the sheet?

Thank you Fluff for your attempt to resolve my project. Hv a great day!
 
Upvote 0
Right click the tab on the sheet you want this to work on, select View code & paste the code into the window that opens up.
Do not change the name of the sub.
 
Upvote 0
Apologies Fluff, i didn't know the way you advised me. Thank u so much. Is very kind of you!
 
Last edited:
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
I am sorry that i bother you again Fluff, just i wanted to incorporate the above code with another one. I mean before the "End Sub" of a previous command/code, i would like to paste your above code. I attempted but it doesn't work. Apologies for such query. Many thanks in advance
 
Upvote 0
Would you like to give me some more info?
I do you want me to read your mind? ;)
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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