Adding conditional statement to existing code that shows/hides columns and cells

TheJay

Active Member
Joined
Nov 12, 2014
Messages
364
Office Version
  1. 2019
Platform
  1. Windows
Hello there, I am having a mental block and wondered if someone could please assist?

Existing code
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Check choices made and show/hide rows/columns accordingly
    Sheets("Instalments").Unprotect
        Select Case Target.Address(0, 0)
            Case "G16" 'Tick box
                ActiveSheet.Shapes("CheckBox6").Visible = (Len(Target.Value) > 0)
            Case "C10" 'Temporary debit calculator
                If Target.Value = "No Payments" Then
                    Range("F:F").EntireColumn.Hidden = True
                ElseIf Target.Value = "Credit on Account" Then
                    Range("F:F").EntireColumn.Hidden = False
                ElseIf Target.Value = "Debit on Account" Then
                    Range("F:F").EntireColumn.Hidden = False
                End If
            Case "C20" 'Discount calculator
                If Target.Value = "No Discount" Then
                    Range("21:34").EntireRow.Hidden = True
                    Range("C20").Select
                ElseIf Target.Value = "25% Discount" Then
                    Range("21:24").EntireRow.Hidden = False
                    Range("25:34").EntireRow.Hidden = True
                ElseIf Target.Value = "50% Discount" Then
                    Range("26:29").EntireRow.Hidden = False
                    Range("21:25").EntireRow.Hidden = True
                    Range("30:34").EntireRow.Hidden = True
                ElseIf Target.Value = "50% Discount & 25% Discount" Then
                    Range("31:34").EntireRow.Hidden = False
                    Range("21:30").EntireRow.Hidden = True
                End If
    Sheets("Instalments").Protect
                Range("C20").Select
        End Select
End Sub

I want to hide C17:G18 if a value hasn't been entered into the three cells C16:E16 respectively. Can this be added to the above?

Thank you for your help.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Tried this but it hasn't worked:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Check choices made and show/hide rows/columns accordingly
    Sheets("Instalments").Unprotect
        Select Case Target.Address(0, 0)
          Case "C16:E16" 'Results
                If Target.Value = "" Then
                    Range("17:18").EntireRow.Hidden = True
                    Range("17:18").EntireRow.Hidden = False
                End If[/B]
            Case "G16" 'Tick box
                ActiveSheet.Shapes("CheckBox6").Visible = (Len(Target.Value) > 0)
            Case "C10" 'Temporary debit calculator
                If Target.Value = "No Payments" Then
                    Range("F:F").EntireColumn.Hidden = True
                ElseIf Target.Value = "Credit on Account" Then
                    Range("F:F").EntireColumn.Hidden = False
                ElseIf Target.Value = "Debit on Account" Then
                    Range("F:F").EntireColumn.Hidden = False
                End If
            Case "C20" 'Discount calculator
                If Target.Value = "No Discount" Then
                    Range("21:34").EntireRow.Hidden = True
                    Range("C20").Select
                ElseIf Target.Value = "25% Discount" Then
                    Range("21:24").EntireRow.Hidden = False
                    Range("25:34").EntireRow.Hidden = True
                ElseIf Target.Value = "50% Discount" Then
                    Range("26:29").EntireRow.Hidden = False
                    Range("21:25").EntireRow.Hidden = True
                    Range("30:34").EntireRow.Hidden = True
                ElseIf Target.Value = "50% Discount & 25% Discount" Then
                    Range("31:34").EntireRow.Hidden = False
                    Range("21:30").EntireRow.Hidden = True
                End If
    Sheets("Instalments").Protect
                Range("C20").Select
        End Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,567
Messages
6,114,342
Members
448,570
Latest member
rik81h

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