我在检查范围内有两个条件的算法时遇到问题... 我想在检查范围中的两个条件后分配一个值...
实施例:
我想为D列分配一个值...我的编号范围是ID(1,2,3 ...)。 B列的值仅在ID = 1附近,下一个ID为null,但范围内的所有行都有字符。 所以,我需要根据旁边的表为D列分配一个值。 当列B为TRUE时,则列D = NEGATIVE ...结束,但当列B中的值= FALSE时,检查范围内的组合。
预期结果:
你知道吗?谢谢你的帮助!答案 0 :(得分:4)
繁荣走向了炸药。这将采取如下输入:
并告诉你:
Sub TestIt()
Dim LastRow As Long, CurRow As Long, InLast As Long, FindRng As Range
LastRow = Range("C" & Rows.Count).End(xlUp).Row
For CurRow = 1 To LastRow
If Not Range("B" & CurRow).Value = "" Then
If Range("B" & CurRow + 1).Value = "" Then
InLast = Range("B" & CurRow).End(xlDown).Row - CurRow - 1
Else
InLast = 0
End If
If InLast > LastRow Then InLast = LastRow - CurRow
If InLast > 0 Then Set FindRng = Range(Cells(CurRow, 3), Cells(InLast + CurRow, 3))
Select Case True
Case Range("B" & CurRow).Value = "TRUE"
Range("D" & CurRow).Value = "NEGATIVE"
Case InLast = 0
Range("D" & CurRow).Value = Range("C" & CurRow).Value
Case Not FindRng.Find("POSITIVE", LookIn:=xlValues, LookAt:=xlWhole) Is Nothing _
And Not FindRng.Find("NEGATIVE", LookIn:=xlValues, LookAt:=xlWhole) Is Nothing _
And Not FindRng.Find("NEUTRAL", LookIn:=xlValues, LookAt:=xlWhole) Is Nothing _
And InLast > 0
Range("D" & CurRow).Value = "MIX"
Case Not FindRng.Find("POSITIVE", LookIn:=xlValues, LookAt:=xlWhole) Is Nothing _
And FindRng.Find("NEGATIVE", LookIn:=xlValues, LookAt:=xlWhole) Is Nothing _
And InLast > 0
Range("D" & CurRow).Value = "POSITIVE"
Case FindRng.Find("POSITIVE", LookIn:=xlValues, LookAt:=xlWhole) Is Nothing _
And Not FindRng.Find("NEGATIVE", LookIn:=xlValues, LookAt:=xlWhole) Is Nothing _
And InLast > 0
Range("D" & CurRow).Value = "NEGATIVE"
Case FindRng.Find("POSITIVE", LookIn:=xlValues, LookAt:=xlWhole) Is Nothing _
And FindRng.Find("NEGATIVE", LookIn:=xlValues, LookAt:=xlWhole) Is Nothing _
And Not FindRng.Find("NEUTRAL", LookIn:=xlValues, LookAt:=xlWhole) Is Nothing _
And InLast > 0
Range("D" & CurRow).Value = "NEUTRAL"
'Case Not FindRng.Find("POSITIVE", LookIn:=xlValues, LookAt:=xlWhole) Is Nothing _
' And Not FindRng.Find("NEGATIVE", LookIn:=xlValues, LookAt:=xlWhole) Is Nothing _
' And FindRng.Find("NEUTRAL", LookIn:=xlValues, LookAt:=xlWhole) Is Nothing _
' And InLast > 0
' Range("D" & CurRow).Value = "CASE POSITIVE AND NEGATIVE NO NEUTRAL"
Case Else
Range("D" & CurRow).Value = "ERROR"
End Select
End If
Next CurRow
End Sub
答案 1 :(得分:2)
=IF(ISBLANK(B1),"", IF(B1="TRUE", "NEGATIVE", C1))
答案 2 :(得分:1)
" D1"中的公式是以下是:
=IF(B1=TRUE,"NEGATIVE",IF(B1="","", C1))
粘贴表单" D1"