Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel VBA:如果值不匹配,如何跳过一行_Excel_Vba_Automation - Fatal编程技术网

Excel VBA:如果值不匹配,如何跳过一行

Excel VBA:如果值不匹配,如何跳过一行,excel,vba,automation,Excel,Vba,Automation,我在跳过特定的行命令时遇到问题 如果值比较为True,则执行该行,然后比较为false表示跳过该行并转到下一行 当我运行代码时,我得到一个错误 对象已定义-运行时错误1004 请帮我解决这个问题 If Sheets("Group").Range("F:F" = "Numbers") Then 'Value comparison GoTo Numbers 'Current Call function Else: GoTo Text 'Next Call function

我在跳过特定的行命令时遇到问题

如果值比较为True,则执行该行,然后比较为false表示跳过该行并转到下一行

当我运行代码时,我得到一个错误

对象已定义-运行时错误1004

请帮我解决这个问题

 If Sheets("Group").Range("F:F" = "Numbers") Then 'Value comparison
    GoTo Numbers 'Current Call function
    Else: GoTo Text 'Next Call function
    End If

    Numbers:
    DoEvents
    Call Numbers 'If number based serial call it
    Text:
    DoEvents
    Call Text 'If Text based serial call it
我的截图:

查看我的完整宏

Sub Bass()
Application.ScreenUpdating = False
DoEvents
Call Groupit 'Category All Serial


If Sheets("Group").Range("F:F" = "Numbers") Then
GoTo Numbers
Else: GoTo Text
End If

If Sheets("Group").Range("F:F" = "Text") Then
GoTo Text
Else: GoTo withK
End If

If Sheets("Group1").Range("E:E" = "*K*") Then
GoTo withK
Else: GoTo withoutK
End If

If Sheets("Group1").Range("E:E" <> "*K*") Then
GoTo withoutK
Else: GoTo Lastln
End If

'Bookmarks
Numbers:
DoEvents
Call Numbers 'If number based serial call it
Text:
DoEvents
Call Text 'If Text based serial call it
withK:
DoEvents
Call BothwithK 'If K based serial call it
withoutK:
DoEvents
Call BothwithoutK 'If not"K" based serial call it
Lastln:
DoEvents
Application.ScreenUpdating = True

End Sub
Sub-Bass()
Application.ScreenUpdating=False
多芬特
调用Groupit’类别所有序列
如果图纸(“组”)范围(“F:F”=“编号”),则
转到号码
其他:转到文本
如果结束
如果图纸(“组”)范围(“F:F”=“文本”),则
转到文本
要不然,我就跟你走
如果结束
如果图纸(“第1组”)范围(“E:E”=“*K*”),则
转投
要不然,我就不去了
如果结束
如果图纸(“第1组”)。范围(“E:E”“*K*”),则
无目的地
其他:转到Lastln
如果结束
'书签
编号:
多芬特
呼叫号码“如果基于号码的串行呼叫它
正文:
多芬特
调用文本“如果基于文本的串行调用它
withK:
多芬特
调用BothwithK'如果基于K的串行调用它
没有:
多芬特
调用bothWithout'如果不是基于“K”的串行调用它
Lastln:
多芬特
Application.ScreenUpdating=True
端接头

将forech循环与一些select case语句一起使用

Sub Bass()
Application.ScreenUpdating = False
DoEvents

Dim rngF As Range: Set rngF = Range("F:F")
Dim rngE As Range: Set rngE = Range("E:E")
Dim countNumbers As Integer, countText As Integer, countWithK As Integer, countWithoutK As intteger
countNumbers = 0
countText = 0
countWithK = 0
countWithoutK = 0
For Each cell In rngF
    Select Case cell.Value
        Case "Numbers"
            countNumbers = countNumbers + 1
        Case "Text"
            countText = countText + 1
        Case "*K*"
            countWithK = countWithK + 1
        Case Else
        ' SomethingElse
    End Select
Next cell

If countNumbers > 0 Then
    Call NumbersSub
End If

If countText > 0 Then
    Call TextSub
End If

If countWithK > 0 Then
    Call countWithK
End If

countWithK = 0

For Each cell In rngE
    Select Case cell.Value
        Case "*K*"
            countWithK = countWithK + 1
        Case "*"
            countWithoutK = countWithoutK + 1
        Case Else
           'SomethingElse
    End Select
Next cell

If countWithK > 0 Then
    Call withK
End If
If countWithoutK > 0 Then
    Call withoutK
End If

MsgBox "Done"
End Sub

Sub NumbersSub()
MsgBox "Number found"
End Sub
Sub TextSub()
MsgBox "Text found"
End Sub
Sub withK()
MsgBox "Text with K found"
End Sub
Sub withoutK()
MsgBox "Text without K found"
End Sub

范围
工作表对象的属性不接受像
“F:F”=“number”
这样的参数。如果要筛选值,可以使用。如果你想检查某个值是否出现,那么你可以使用
if Not Sheets(“Group”).Range(“F:F”).Find(What:=“Numbers”,LookIn:=xlValues,LookAt:=xlother)什么都不是,那么我想你是想标记@HTH@HTH此代码可以工作,但会自动关闭sheet@baskar,在显示的代码中不可见工作簿结束语句。我猜是在另一个子/函数中,控件在
sub-Bass()
错误后返回到该子/函数中,原因是我已经向您解释了,如果您能解释在编写时应该发生什么,例如呼叫号码?此代码有编译错误请参见此图[link]此错误是由于项目中尚未定义某些子名称而导致的。为了测试的目的,我已经用一些额外的sub更新了代码。现在可以工作了。但是Msgbox弹出窗口会出现在每一行进程中,所以我忽略了行。并在最后一个Sub中添加Submacro调用。。。谢谢你的回答……我在上面提到的答案中有问题。它重复基于循环的输入行计数。但是我只需要调用Each子函数一次,您可以在select case语句中插入一个计数器来代替for,同时循环每个列。如果某些情况为真,则可以将计数器设置为每次有匹配项时加1。完成第一个循环后,检查计数器是否高于0,如果为true,则只调用子例程一次,并在每次迭代列后执行该操作。我已经更新了代码以反映这一添加。