VBA hide/unhide

Cancyy

New Member
Joined
Feb 12, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi all,

please could you help me update this button code.

Sub Commission()
Dim r As Range, c As Range
Set r = Range("E32:E34")
Application.ScreenUpdating = False
For Each c In r
If c.EntireRow.Hidden = True Then
c.EntireRow.Hidden = False
Else
If Len(c.Text) = 0 Then
c.EntireRow.Hidden = True
Else
c.EntireRow.Hidden = False
End If
End If
Next c
Application.ScreenUpdating = True
End Sub

I would like to hide empty cell - depending where I enter the value.
(if I entered value in cell E32 hide empty row E33 and show result E34 and reverse. If both cells are empty hide all rows)
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Welcome to the Board!

I find this explanation a big confusing:
(if I entered value in cell E32 hide empty row E33 and show result E34 and reverse. If both cells are empty hide all rows)
Could you maybe try explaining it again, in more detail, maybe show us a few examples along with your expected results?
 
Upvote 0
Hi, and thank you.
Now I see that what I want is described rather clumsily.:rolleyes:
I came up with the solution on my own :biggrin:

firs I entered formula in Cell B34
Capture1.JPG

when you enter percentage in B32 row 33 is hidden
Capture2.JPG

if you enter percentage in cell B33 row 32 is hidden
Capture3.JPG

when there is no commission (empty cells B32 and B33) - all rows 32,33 and 34 are hidden

I hope that pictures explain better than my words :)

VBA Code:
Sub Commission()

 
    Dim r As Range, c As Range
    Set r = Range("B32:B34")
    Application.ScreenUpdating = False

   For Each c In r
       
        If c.EntireRow.Hidden = True Then
            c.EntireRow.Hidden = False
        Else
            If c.Value = 0 Then
                c.EntireRow.Hidden = True
            Else
                c.EntireRow.Hidden = False
            End If
        End If
   
    Next c

    Application.ScreenUpdating = True
          

End Sub

There's a chance there's a better solution, but this works for me.
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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