VBA code multiple conditions hidden

fjacruz

New Member
Joined
Feb 15, 2019
Messages
7
dear all,

could you please help me to correctly perform the following code:


Private Sub CommandButton1_Click()
If Range("E2").Value = "1" Then
Rows("50:102").EntireRow.Hidden = True
End If
If Range("E2").Value = "2" Then
Rows("32:105").EntireRow.Hidden = False
End If
If Range("E2").Value = "2" Then
Rows("68:102").EntireRow.Hidden = True
End If
If Range("E2").Value = "3" Then
Rows("86:105").EntireRow.Hidden = False
End If
If Range("E2").Value = "3" Then
Rows("86:102").EntireRow.Hidden = True
End If
If Range("E2").Value = "4" Then
Rows("32:105").EntireRow.Hidden = False
End If
If Range("E2").Value > "4" Then
Rows("32:105").EntireRow.Hidden = True
End If
If Range("E2").Value < "1" Then
Rows("32:105").EntireRow.Hidden = True
End If
If Range("E2").Value < 1 Or Range("C3").Value > 4 Then
Range("32:105").EntireRow.Hidden = False
End If
End Sub

When excel opened, cell E2 is equal to zero and range 32:105 is hidden. when is put E2 equals to 0 it opened all cells but what I want it's not opening nothing when it's below 1 and greather than 4. For instance when I put E2 equals to 1 an execute button it does not open range 32:50. It seems it is not working because I am not following a certain path...

thank you
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
First thing to do try is removing the "" around the numbers, for example.
Code:
If Range("E2").Value = 1 Then
    Rows("50:102").EntireRow.Hidden = True
End If
 
Upvote 0
it works..suppose now I want to execute E2=1 and after that execute E2=2. It does not work the 2nd...
I wrote the following:

Private Sub CommandButton1_Click()
If Range("E2").Value = 1 Then
Rows("7:35").EntireRow.Hidden = True
End If
If Range("E2").Value = 12 Then
Rows("7:25").EntireRow.Hidden = True
End If
End Sub

I am not to unhide step 1 neither hide step 2...meanwhile em corrected " " on my first code but still not fix.
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,034
Members
448,543
Latest member
MartinLarkin

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