限制在ElseIf条件下吗? [英] Limit to ElseIf Conditions?

查看:99
本文介绍了限制在ElseIf条件下吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有一些VBA代码旨在根据单元格中的值进行一些操作.读取单元格中的值,并相应地运行代码.可以正常工作.

So I have some VBA code designed to go through a few things based on a value in a cell. The value in the cell is read and the code runs accordingly. This works without issue with.

If Target.Value = "something" Then
End If
ElseIf Target.Value = "something2" Then
End If
ElseIf Target.Value = "something3" Then
End If
ElseIf Target.Value = "something4" Then
End If

那很好,但是,如果我添加一个附加的ElseIf条件,则会出现没有If的Else"编译器错误.在第五种情况下将ElseIf更改为Else不能解决问题.我的问题是我可以运行的ElseIf条件的数量是否有限制?从字面上看,我只需要完成我要做的第五件事即可.我很肯定条件内的代码没有错误.

That works perfectly, however if I add an additional ElseIf condition I get the compiler error of "Else without If". Changing ElseIf to Else on the fifth condition doesn't fix the issue. My question is that is there a limit to the amount of ElseIf conditions I can run? I literally only need this fifth one to be entirely done with what I am trying to do. I am positive the code within the condition has no errors.

推荐答案

如果结束"仅在结尾:

If Target.Value = "something" Then
    'Do something
ElseIf Target.Value = "something2" Then
    'Do something
ElseIf Target.Value = "something3" Then
    'Do something
ElseIf Target.Value = "something4" Then
    'Do something
End If

这篇关于限制在ElseIf条件下吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆