Help with if then else

pvzshark

Repeated rules violations
Joined
Feb 26, 2020
Messages
23
Office Version
  1. 2013
Platform
  1. Windows
I have 4 buttons - 2017 to 2020
then 12 buttons jan to desember.

When you click 2017 then i hide all cells that is in that range. the same for 2018 etc

then if you do not want to see jan you can click on jan then it should take jan away, but because the trigger is at hide and you click jan then the jan 2017 becomes unhidded as the 2017 has hidden it.

I have tried to fix it with this iff then statement but now it only reads the first iff statement. please help

VBA Code:
Private Sub b2017_Click()
Range("EE2").Value = (Range("EE2").Value + 1) Mod 1
Me.OLEObjects(1).Object.Caption = IIf(Range("EE2").Value = 0, "20170", "2017a")
Set xAddress = Range("C:C,H:H,M:M,R:R,W:W,AB:AB,AG:AG,AL:AL,AQ:AQ,AV:AV,BA:BA,BF:BF,BK:BK,BQ:BQ")
If xAddress.EntireColumn.Hidden = True Then
xAddress.EntireColumn.Hidden = False
Else
xAddress.EntireColumn.Hidden = True
End If
End Sub

Private Sub ToggleButton1_Click()
Range("EF2").Value = (Range("EF2").Value + 1) Mod 1
Me.OLEObjects(16).Object.Caption = IIf(Range("EF2").Value = 0, "20180", "2018a")
Set xAddress = Range("D:D,I:I,N:N,S:S,X:X,AC:AC,AH:AH,AM:AM,AR:AR,AW:AW,BB:BB,BG:BG,BL:BL,BR:BR")
If xAddress.EntireColumn.Hidden = True Then
xAddress.EntireColumn.Hidden = False
Else
xAddress.EntireColumn.Hidden = True
End If
End Sub

Private Sub ToggleButton2_Click()
Range("EG2").Value = (Range("EG2").Value + 1) Mod 1
Me.OLEObjects(2).Object.Caption = IIf(Range("EG2").Value = 0, "20190", "2019a")
Set xAddress = Range("E:E,J:J,O:O,T:T,Y:Y,AD:AD,AI:AI,AN:AN,AS:AS,AX:AX,BC:BC,BH:BH,BM:BM")
If xAddress.EntireColumn.Hidden = True Then
xAddress.EntireColumn.Hidden = False
Else
xAddress.EntireColumn.Hidden = True
End If
End Sub
Private Sub ToggleButton3_Click()
Range("EH2").Value = (Range("EH2").Value + 1) Mod 1
Me.OLEObjects(3).Object.Caption = IIf(Range("EH2").Value = 0, "20200", "2020a")

Set xAddress = Range("F:F,K:K,P:P,U:U,Z:Z,AE:AE,AT:AT,AJ:AJ,AO:AO,AT:AT,AY:AY,BD:BD,BI:BI,BN:BN")
If xAddress.EntireColumn.Hidden = True Then
xAddress.EntireColumn.Hidden = False
Else
xAddress.EntireColumn.Hidden = True
End If
End Sub


Private Sub ToggleButton4_Click()
Range("EI2").Value = (Range("EI2").Value + 1) Mod 1
Me.OLEObjects(4).Object.Caption = IIf(Range("EI2").Value = 0, "JAN0", "JANa")
Set xAddress = Range("C:C,D:D,E:E,F:F,g:g")
Set a7Address = Range("C:C")
Set a8Address = Range("D:D")
Set a9Address = Range("E:E")
Set a10Address = Range("F:F")
If Range("ee2") = "0" And Range("ei2") = "1" Then
a8Address.EntireColumn.Hidden = True
ElseIf Range("ef2") = "0" And Range("ei2") = "1" Then
a7Address.EntireColumn.Hidden = True
ElseIf Range("eg2") = "0" And Range("ei2") = "1" Then
a9Address.EntireColumn.Hidden = True
ElseIf Range("eh2") = "0" And Range("ei2") = "1" Then
a10Address.EntireColumn.Hidden = True
ElseIf Range("ee2") = "1" And Range("ei2") = "1" Then
a7Address.EntireColumn.Hidden = True
ElseIf Range("ef2") = "1" And Range("ei2") = "1" Then
a8Address.EntireColumn.Hidden = True
ElseIf Range("eg2") = "1" And Range("ei2") = "1" Then
a9Address.EntireColumn.Hidden = True
ElseIf Range("eh2") = "1" And Range("ei2") = "1" Then
a10Address.EntireColumn.Hidden = True
ElseIf Range("ee2") = "1" And Range("ei2") = "0" Then
a7Address.EntireColumn.Hidden = True
ElseIf Range("ef2") = "1" And Range("ei2") = "0" Then
a8Address.EntireColumn.Hidden = True
ElseIf Range("eg2") = "1" And Range("ei2") = "0" Then
a9Address.EntireColumn.Hidden = True
ElseIf Range("eh2") = "1" And Range("ei2") = "0" Then
a10Address.EntireColumn.Hidden = True
ElseIf Range("ee2") = "0" And Range("ei2") = "0" Then
a7Address.EntireColumn.Hidden = False
ElseIf Range("ef2") = "0" And Range("ei2") = "0" Then
a8Address.EntireColumn.Hidden = False
ElseIf Range("eg2") = "0" And Range("ei2") = "0" Then
a9Address.EntireColumn.Hidden = False
Else
xAddress.EntireColumn.Hidden = True
End If
End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,215,039
Messages
6,122,802
Members
449,095
Latest member
m_smith_solihull

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