我正在尝试构建逻辑,如果特定工作表中的特定单元格填充了特定字符串,它会跳过运行该子程序并继续下一个。我认为这是迄今为止我最接近的一些研究尝试:
Dim Rng_1 As Range
Dim x_sheet As Worksheet
Dim Value_X
Value_X = "<>Could not generate report for*"
Set x_sheet = ActiveWorkbook.Worksheets("worksheet_name")
Set Rng_1 = x_sheet.Range("B8")
If Rng_1.value = Value_X Then
'run code
End If
'It should continue from here if the referenced cell did contain the string.
无论我如何编辑不包含值,或者即使我添加“else if”,运行上面的代码总是会跳过代码。在这一点上,我什至不确定我是否走在正确的轨道上。
Referenced Sheet
最佳答案
Like
处理通配符时需要使用比较运算符。 '不匹配'是Not this Like that
.您不添加 <>
运算符产生“不匹配”。
您需要Else
如果你想要A计划和B计划。
Value_X = "Could not generate report for*" 'removed <>
Set x_sheet = ActiveWorkbook.Worksheets("worksheet_name")
Set Rng_1 = x_sheet.Range("B8")
If Not Rng_1.value Like Value_X Then
Debug.Print "msg not found"
'run code
Else
Debug.Print "msg found"
'It should continue from here if the referenced cell did contain the string.
End If
首先,从您的样本数据看来,您还可以测试
IsNumeric(Rng_1.value)
.
关于excel - VBA - If 语句引用不同工作表中单元格中的特定文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55563340/