• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Run code on two if statements

ManuGrim

New Member
Hello,

I have a piece of code that is a combination of two cell values. One value is changed by a dropdown and the other cell changes its value by a VLOOKUP formula.

Here is my work so far... (code in Sheet1 and Module1)

Thank you very much!
 

Attachments

  • Hide-v1.xlsm
    18.6 KB · Views: 7
In making the columns hide/unhide when the value in the drop-down and the vlookup change...I made the columns hide when the drop-down value change, but it does not change according to the vlookup...
Thanks
 
@ManuGrim

Please Change Your Code to This

Code:
Sub Worksheet_change(ByVal Target As Range)
   
  If Target.Address = "$C$1" Then
  Select Case Target.Value
  Case Is = "House"
  Sheet1.Range("D:ZZ").EntireColumn.Hidden = True
  Sheet1.Range("D:F").EntireColumn.Hidden = False
  Case Is = "Car"
  Sheet1.Range("D:ZZ").EntireColumn.Hidden = True
  Sheet1.Range("G:I").EntireColumn.Hidden = False
  Case Is = "Dog"
  Sheet1.Range("D:ZZ").EntireColumn.Hidden = True
  Sheet1.Range("J:L").EntireColumn.Hidden = False
  Case Is = "Cat"
  Sheet1.Range("D:ZZ").EntireColumn.Hidden = True
  Sheet1.Range("M:O").EntireColumn.Hidden = False
  End Select

  End If
   
  If Target.Address = "$C$2" Then
  Select Case Target.Value
  Case "Daily"
  Call Daily
  Case "Weekly"
  Call Weekly
  Case "Monthly"
  Call Monthly
  End Select
   
  End If

Hope it solves other wise pls inform

Thanks
 
Thanks for shortening the code a bit :)

The problem persists. When I select "Dog" from the dropdown, the columns hide, which is perfect. But I also want that the rows hide, so that for case "Dog" I only see two rows. It works if I select the formula and hit Enter. But I would like it to automatically update...

So I need the two ifs to hide both columns and rows.

Thanks
 
Is there a way to say:

Code:
Select case target.value And target.value2
Case for target.value is = abc
Case for target.value2 is = def
 
@ All

I want the columns and the rows to hide at the same time when 2 cells change.
My code is dependent on 2 cells, C1 and C2.
C1 is a dropdown list. C2 changes depending on C1 with a vlookup.
When I select from C1 dropdown "Car" that determines C2 to be "Weekly".
The columns hide nicely but I also want for the Weekly macro to be enabled and for the rows to hide, so that I can only see Week1, Week2...without the repetition.

Thus I want both the rows and columns to hide.
Columns hide when C1 changes.
Rows hide when C2 changes.

I really hope you guys can help me.

Thank you very much.
 
SOLVED!!!

Code:
Sub Worksheet_change(ByVal Target As Range)
   
  If Target.Address = "$C$1" Then
  Select Case Target.Value
  Case Is = "House"
  Sheet1.Range("D:ZZ").EntireColumn.Hidden = True
  Sheet1.Range("D:F").EntireColumn.Hidden = False
  Case Is = "Car"
  Sheet1.Range("D:ZZ").EntireColumn.Hidden = True
  Sheet1.Range("G:I").EntireColumn.Hidden = False
  Case Is = "Dog"
  Sheet1.Range("D:ZZ").EntireColumn.Hidden = True
  Sheet1.Range("J:L").EntireColumn.Hidden = False
  Case Is = "Cat"
  Sheet1.Range("D:ZZ").EntireColumn.Hidden = True
  Sheet1.Range("M:O").EntireColumn.Hidden = False
  End Select
  End If
   
  If Range("$C$2").Text = "Daily" Then
  Call Daily
  End If
  If Range("$C$2").Text = "Weekly" Then
  Call Weekly
  End If
  If Range("$C$2").Text = "Monthly" Then
  Call Monthly
  End If

End Sub

Thanks guys!
 
Back
Top