Excel 布尔和If语句
我有一个代码,可以在循环中将单元格数组转换为字符串。如果单元格包含特定字符串,它会正确地将trues放入boolean found变量中,但是会跳过以这些变量为true目标的if语句,并且只执行最后一条else语句。我不知道为什么会这样,也不想知道为什么if语句不能将变量视为true。提前谢谢Excel 布尔和If语句,excel,vba,if-statement,boolean,Excel,Vba,If Statement,Boolean,我有一个代码,可以在循环中将单元格数组转换为字符串。如果单元格包含特定字符串,它会正确地将trues放入boolean found变量中,但是会跳过以这些变量为true目标的if语句,并且只执行最后一条else语句。我不知道为什么会这样,也不想知道为什么if语句不能将变量视为true。提前谢谢 trimmedValX = Trim$(ur(r, m(6))) *creates the string Found1 = InStr(trimmedValX, "still sold")
trimmedValX = Trim$(ur(r, m(6))) *creates the string
Found1 = InStr(trimmedValX, "still sold") *checks to see if string is in the created string, if it is variable is set as True
Found2 = InStr(trimmedValX, "Still sold")
Found3 = InStr(trimmedValX, "Discontinued")
If Found3 = True Then
cell1.Interior.Color = rColor
ElseIf Found1 = True or Found2 = True Then
cell1.Interior.Color = gColor
Else
cell1.Interior.Color = mColor
End If
InStr
不返回布尔值,而是返回子字符串的起始位置。试着用这个代替
InStr
不返回布尔值,而是返回子字符串的起始位置。试着用这个代替
我会建议一些根本不需要说明的东西
trimmedValX = Trim$(ur(r, m(6)))
With cell1.Interior
If UCase(trimmedValX) Like "*DISCONTINUED*" Then
.Color = rColor
ElseIf UCase(trimmedValX) Like "*STILL SOLD*" Then
.Color = gColor
Else
.Color = mColor
End If
End With
我会建议一些根本不需要说明的东西
trimmedValX = Trim$(ur(r, m(6)))
With cell1.Interior
If UCase(trimmedValX) Like "*DISCONTINUED*" Then
.Color = rColor
ElseIf UCase(trimmedValX) Like "*STILL SOLD*" Then
.Color = gColor
Else
.Color = mColor
End If
End With