在两个范围内检查algorithm

我有两个条件范围检查algorithm的问题…我想分配一个值后检查范围内的两个条件…

例: 在这里输入图像描述

我想分配一个值列D …我有编号的范围与ID(1,2,3 …)。 B列只在ID = 1附近有值,下一个ID为空,但范围内的所有行都有字符。 所以,我需要根据旁边的表格为D列赋值。 当B列为TRUE时,则D列中的值= NEGATIVE …结束,但当B列中的值= FALSE时检查组合的范围。

预期结果: 在这里输入图像描述

你有好主意吗? 感谢帮助!

轰隆轰炸。 这将需要像这样的input:

在这里输入图像说明

给你这个:

在这里输入图像说明

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 
 =IF(ISBLANK(B1),"", IF(B1="TRUE", "NEGATIVE", C1)) 

“D1”中的公式如下:

 =IF(B1=TRUE,"NEGATIVE",IF(B1="","", C1)) 

粘贴“D1”