Hide Column on Another Sheet

LPalmer

New Member
Joined
Oct 8, 2019
Messages
12
Hello All,

I have the macro below that I was hoping to get some assistance on. Macro was working fine until I tried to both hide/unhide rows on the current worksheet and hide/unhide column on another worksheet based on response given in cell C24. Feel like it is something simple with the end if statements but just not getting it. Thanks!

Code:
Private Sub Worksheet_Change(ByVal Target As Range)   If Target.CountLarge > 1 Then Exit Sub
   
   If Target.Address(0, 0) = "C8" Then
      'Message Box Appears or Unhides Rows if Value is less than 25
      If Target < 25 And Target <> "" Then
         Rows("10:11").EntireRow.Hidden = False
         MsgBox "Unless the plan has less than 250 participants, it would be unusual to have a sample size of less than 25. Verify that this is the sample size that was determined to be appropriate."
         
      'Hides Rows if Value is equal to or greater than 25
      ElseIf Target >= 25 Or Target = "" Then
         Rows("10:11").EntireRow.Hidden = True
        End If
         
    ElseIf Target.Address(0, 0) = "C12" Then
      'Hides Rows if Cell C12 equals "No"
      If Target = "YES" Then
         Rows("13:15").EntireRow.Hidden = False
      ElseIf Target = "NO" Then
         Rows("13:15").EntireRow.Hidden = True
         End If
         
'Why Don't you give Task 1C and Task 1D a shot!
         
     ElseIf Target.Address(0, 0) = "C24" Then
      'Unhides rows if C24 says "Yes"
      If Target = "YES" Then
         Rows("25").EntireRow.Hidden = False
         Rows("26").EntireRow.Hidden = False
         With Worksheets("2)Participant Eligibility")
            .Columns("F:F").EntireColumn.Hidden = False
         End With
         
      If Target = "NO" Then
         Rows("25").EntireRow.Hidden = True
         Rows("26").EntireRow.Hidden = True
         With Worksheets("2)Participant Eligibility")
            .Columns("F:F").EntireColumn.Hidden = True
         End With
         End If
         
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
An End If is missing:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.CountLarge > 1 Then Exit Sub
   
   If Target.Address(0, 0) = "C8" Then
      'Message Box Appears or Unhides Rows if Value is less than 25
      If Target < 25 And Target <> "" Then
         Rows("10:11").EntireRow.Hidden = False
         MsgBox "Unless the plan has less than 250 participants, it would be unusual to have a sample size of less than 25. Verify that this is the sample size that was determined to be appropriate."
         
      'Hides Rows if Value is equal to or greater than 25
      ElseIf Target >= 25 Or Target = "" Then
         Rows("10:11").EntireRow.Hidden = True
      End If
         
  ElseIf Target.Address(0, 0) = "C12" Then
      'Hides Rows if Cell C12 equals "No"
      If Target = "YES" Then
         Rows("13:15").EntireRow.Hidden = False
      ElseIf Target = "NO" Then
         Rows("13:15").EntireRow.Hidden = True
      End If
         
'Why Don't you give Task 1C and Task 1D a shot!
         
  ElseIf Target.Address(0, 0) = "C24" Then
      'Unhides rows if C24 says "Yes"
      If Target = "YES" Then
         Rows("25").EntireRow.Hidden = False
         Rows("26").EntireRow.Hidden = False
         With Worksheets("2)Participant Eligibility")
            .Columns("F:F").EntireColumn.Hidden = False
         End With
[COLOR=#ff0000]      End If[/COLOR]
      If Target = "NO" Then
         Rows("25").EntireRow.Hidden = True
         Rows("26").EntireRow.Hidden = True
         With Worksheets("2)Participant Eligibility")
            .Columns("F:F").EntireColumn.Hidden = True
         End With
      End If
[COLOR=#ff0000]  End If[/COLOR]
End Sub
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,184
Members
452,615
Latest member
bogeys2birdies

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