根据其他两个列的值选择一个范围
我有两个列的O6:P范围,可评估J中的数据行并显示通过或失败。 O和P中的结果并不总是相同的。一个可以显示通过,另一个将失败。 我这里有的代码大部分都可以使用。除了它选择o或p等于通过的列中的范围。我需要它只能选择两个列通过的范围。有没有办法将其拆分,以便它仅选择J中的j和P中两个值的范围?
Dim lastrow As Long
Dim xRg As Range, yRg As Range, nRg As Range, mRg As Range
'Selecting range = to PASS
With ShNC1
lastrow = .Cells(.Rows.Count, "J").End(xlUp).Row
Application.ScreenUpdating = False
For Each xRg In .Range("O6:P" & lastrow)
If UCase(xRg.Text) = "PASS" Then
If yRg Is Nothing Then
Set yRg = .Range("J" & xRg.Row)
Else
Set yRg = Union(yRg, .Range("J" & xRg.Row))
End If
End If
Next xRg
End With
If Not yRg Is Nothing Then yRg.Select
I have two columns with the range O6:P that evaluate the row of data in J and display Pass or Fail. The results in O and in P are not always the same. One can display Passing and the other will have failed.
The code I have here works for the most part. Except that it is selecting the range in column J where either O or P are equal to PASS. I need it to only select the range where both columns are Passing. is there a way to split this up so that it will only select the range in J where both values in the row for O and P are passing?
Dim lastrow As Long
Dim xRg As Range, yRg As Range, nRg As Range, mRg As Range
'Selecting range = to PASS
With ShNC1
lastrow = .Cells(.Rows.Count, "J").End(xlUp).Row
Application.ScreenUpdating = False
For Each xRg In .Range("O6:P" & lastrow)
If UCase(xRg.Text) = "PASS" Then
If yRg Is Nothing Then
Set yRg = .Range("J" & xRg.Row)
Else
Set yRg = Union(yRg, .Range("J" & xRg.Row))
End If
End If
Next xRg
End With
If Not yRg Is Nothing Then yRg.Select
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以循环循环o,并使用
偏移
检查p:You could loop through just O and use
Offset
to check P:#MS-Excel#
输入或将此公式复制到要输出结果的空白单元中:
提示:在此公式中:
A2:A15:是您想找到文本发生的最大次数的数据列表。
#Ms-Excel#
Enter or copy this formula into a blank cell where you want to output the result:
Tips: In this formula:
A2:A15: is the data list that you want to find the greatest number of times a text occurs.