我正在尝试编写宏,因此当用户选择的组合框值中存在相同的值时,它应该在下面的单元格中输出“已检查”。这里的代码运行良好:
Dim SrchRng As Range, cel As Range
Set SrchRng = Range("A3:G11")
For Each cel In SrchRng
If InStr(1, cel.Value, m1_day1.Value) > 0 Then
cel.Offset(1, 0).Value = "Checked"
End If
Next cel
问题是当m1_day1.Value
为'2'时,程序将在包含'2'的所有数字下面的单元格中输出“Checked”:12,20,22 24等。
答案 0 :(得分:0)
正确显示:(无需替换)
If InStr(1, ","&cel.Value&",", ","&m1_day1.Value&",") > 0 Then
让单元格为"3,6,14,26"
,它将更改为",3,6,14,26,"
并查找",6,"
=> 26不会计数
答案 1 :(得分:0)
使用它。它只会替换您从组合框中选择的值。
Dim SrchRng As Range, cel As Range
Set SrchRng = Range("A3:G11")
For Each cel In SrchRng
If cel.Value = Val(m1_day1.Value) Then
cel.Offset(1, 0).Value = "Checked"
End If
Next cel