I am trying to show a hidden column based on an option of my dropdown. For a single row it works fine but when I want to extend my Range for 10 rows
If Range("$CF$5: $CF$15") = "Others" Then
Tt displays a Runtime error 13.
Below is my code. Thanks for helping me out.
If Range("$CF$5") = "Others" Then
ActiveSheet.Columns("CG").EntireColumn.Hidden = False
Else
ActiveSheet.Columns("CG").EntireColumn.Hidden = True
End If
How about this? This assumes that if a single cell in the range is set to "Others" that the CG column will be shown, and if none them are, CG will be hidden. Not sure if that's what you're really after?
You can't compare the value in the range like you are doing it.
If Range("$CF$5: $CF$15") = "Others"
There are many ways to do the comparison. Looping through the range is the most common way. Below is a another way to check if all the cells in a vertical range have the same value.
Is this what you are trying?
EDIT:
And if you want to Show/Hide the column even if there is one instance of "Others` then also you don't need a loop. See this