Evaluate Multiple Ranges

DBaker7777

Board Regular
Joined
Feb 3, 2009
Messages
53
Office Version
  1. 365
  2. 2016
The code below only looks in the Range ("U41:U1000") however I would also like it to check Range("W41:W1000"), but I can't seem to get it to include that range as well. I have attempted Range("U41:U1000", "W41:W1000"), but that did not provide the results I was looking for. I need it to check both ranges then hide the row if it does not equal U38. It seemed like it was only looking in Range("W41:W1000") each time.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveWorkbook.ActiveSheet.Unprotect
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
If Target.Row = 38 Then
For Each c In Range("U41:U1000")
If c.Value = Range("U38").Value Then
c.EntireRow.Hidden = False
Else
c.EntireRow.Hidden = True
End If
Next c
End If
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
ActiveWorkbook.ActiveSheet.Protect
End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
When I tried that it seems to be only evaluating Range("W41:W1000") as it will not provide me with any results if Range("U41:U1000") = "U38"
 
Upvote 0
It should be checking both columns. Try this on a blank sheet - it will colour all the cells in the range yellow:

Code:
Sub test()
Dim c As Range
For Each c In Range("U41:U1000,W41:W1000")
    c.Interior.ColorIndex = 6
Next c
End Sub
 
Upvote 0
ADVERTISEMENT
It did indeed color both ranges, but could this be my problem:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
end sub
 
Upvote 0
This happens and starts the trigger for evaluating which rows should be visible and which ones shouldn't be visible. The value in U38 is "True" so when it sees a true in either U or W it should not hide the row, but it seems to be doing on the the trues in column W and not even evaluating column U. I checked to ensure there were in fact trues in column U and there were. Not sure why it is not working.
 
Upvote 0

Forum statistics

Threads
1,196,480
Messages
6,015,450
Members
441,896
Latest member
clomah

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