Worksheet_Change(ByVal Target As Range) - Two Condition

bsquad

Board Regular
Joined
Mar 15, 2016
Messages
194
I have dropdowns in Cells(44,1) and Cells(44,6) with simple values of Yes or No
I am attempting to do a ByVal but I need allow the user to select in any order - meaning changing the value of Cells(44,6) first and Cells(44,1) second and vice versa.

I have tried AND in my statements as well and nothing seems to be working - I am pretty open at this point.
I am also going to need to put 7 more rows of these - but I am not sure if that would make a difference - the conditions are row based so (45,1) and (45,6) have no association to row 44's


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = Cells(44, 1).Address Then
        If Target.Value = "No" Then
            If Cells(44, 6).Value = "No" Then
                ThisWorkbook.Worksheets(8).Visible = False
            Else
                ThisWorkbook.Worksheets(8).Visible = True
            End If
        Else
            ThisWorkbook.Worksheets(8).Visible = True
        End If
    End If
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi ,

See if this works.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
            With Target
                 If .Column <> 1 And .Column <> 6 Then Exit Sub
                 If .Row < 44 Or .Row > 50 Then Exit Sub
                 If ((Cells(.Row, 1) = vbNullString) Or (Cells(.Row, 6) = vbNullString)) Then Exit Sub
                 
                 If ((.Column = 1 And .Value = "Yes") Or (.Column = 6 And .Value = "Yes")) Then
                    ThisWorkbook.Worksheets(8).Visible = True
                 Else
                    ThisWorkbook.Worksheets(8).Visible = False
                 End If
            End With
End Sub
 
Upvote 0
Thank you for the reply,
I was able to figure it out. the one you had posted was still hiding the tab if either Col 1 or Col 6 was = No
no worries though, appreciate the post


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A44")) Is Nothing Then
        If Target.Value = "No" And Range("F44").Value = "No" Then
            ThisWorkbook.Worksheets(8).Visible = False
        Else
            ThisWorkbook.Worksheets(8).Visible = True
        End If
    End If
End Sub
 
Upvote 0
How about

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

     ThisWorkbook.Worksheets(8).Visible = IIF((Range("A44").Value="No") And (Range("F45").Value = "No")), xlSheetHidden, xlSheetVisible)

End If
 
Upvote 0
Mikerickson,

I am getting a syntax error, I tried removing a parenthesis off of the last 'No' and also tried adding an additional parenthesis to the first 'Range' to resolve the syntax, but no joy. I love the approach with this one though, I don't think I've ever seen it like this before. Let me know your thoughts on how to resolve - if you are still up to it.
 
Upvote 0
Mikerickson,

I did originally try that and it didn't work, but looking at it closer I saw the A44, and F45 when I needed F44, but this works amazing and like I mentioned haven't seen this approach before so I really appreciate it thank you.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,161
Members
453,021
Latest member
Justyna P

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