Selection_Change question

MOB

Well-known Member
Joined
Oct 18, 2005
Messages
1,055
Office Version
  1. 365
Platform
  1. Windows
I'm using this;

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Range("C3").Value = 28 Then
        Columns("AK:AM").EntireColumn.Hidden = True
    Else
   If Range("C3").Value = 29 Then
        Columns("AL:AM").EntireColumn.Hidden = True
    Else
   If Range("C3").Value = 30 Then
        Columns("AM").EntireColumn.Hidden = True
   Else
        Columns("AK:AM").EntireColumn.Hidden = False
    End If
     End If
      End If
End Sub

Feel free to improve it lol..............

Anyway, my question is this - cell C3 contains a number (28-31) and the code hides columns based on this value.

However C3 is a formula driven by a data validation cell in cell C2 - so if the user changes the value in C2, the columns will not hide until you click on C3

Is there a simple fix for this?
 
I've had a try but it wont quite work - here are my 2 bits of code, how should I combine them?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Columns("D")) Is Nothing Then _
    MsgBox ("IMPORTANT - Please check funding splits agree before saving!")
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
 
    If Target.Address <> "$C$2" Then Exit Sub
    
    Select Case Range("C3").Value
        Case 28
            Columns("AK:AM").Hidden = True
    
        Case 29
            Columns("AM").Hidden = True
    
        Case 30
            Columns("AK:AM").Hidden = False
    End Select
End Sub
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column =4 Then
    MsgBox ("IMPORTANT - Please check funding splits agree before saving!")
End IF

If Target.Address <> "$C$2" Then Exit Sub
    Select Case Target
        Case 28 : Columns("AK:AM").EntireColumn.Hidden = True
        Case 29 : Columns("AL:AM").EntireColumn.Hidden = True
        Case 30 : Columns("AM").EntireColumn.Hidden = True
        Case Else : Columns("AK:AM").EntireColumn.Hidden = False         
    End Select
End Sub
lenze
 
Upvote 0
Thanks to you both - I now have it working perfectly!

:)
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,855
Members
449,096
Latest member
Erald

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